$(window).load(function() { 
	$('div.objecttxtbook').each(function() { $(this).objectLoad(); $(this).objectTxtBook(); $(this).objectBox('boxmid'); });
	$('div.objecttxtbox').each(function() { $(this).objectLoad(); $(this).objectTxtBox(); $(this).objectBox('boxmid'); });
	$('div.objecttxtchannel').each(function() { $(this).objectLoad(); $(this).objectTxtChannel(); $(this).objectBox('boxmid'); });
	$('div.objecttxtreg').each(function() { $(this).objectLoad(); $(this).objectTxtImg(); });
	$('div.objecttxttab').each(function() { $(this).objectLoad(); $(this).objectTxtTab(); $(this).objectBox('boxmid'); });
	$('div.objecttxtticker').each(function() { $(this).objectLoad(); $(this).objectTxtTicker(0.125); $(this).objectClick(); $(this).objectBox('boxmid'); });
	$('div.objectimgreg').each(function() { $(this).objectLoad(); });
	$('div.objectimgbox').each(function() { $(this).objectLoad(); $(this).objectImgBox(); $(this).objectBox('boxmid'); });
	$('div.objectimggallery').each(function() { $(this).objectLoad(); $(this).objectImgGallery(55); $(this).objectBox('boxmid'); });
	$('div.objectimgthumb').each(function() { $(this).objectLoad(); $(this).objectImgThumb(); $(this).objectBox('boxmid'); });
	$('div.objectimgticker').each(function() { $(this).objectLoad(); $(this).objectImgTicker(2000); $(this).objectBox('boxmid'); });
	$('div.objectimgpopup').each(function() { $(this).objectLoad(); $(this).objectImgPopup(); $(this).objectBox('boxmid'); });
	$('div.objectdocreg').each(function() { $(this).objectLoad(); });
	$('div.objectdocbox').each(function() { $(this).objectLoad(); $(this).objectBox('boxmid'); });
	$('div.objecthtmlreg').each(function() { $(this).objectLoad(); });
	$('div.objecthtmlbox').each(function() { $(this).objectLoad(); $(this).objectBox('boxmid'); });
	$('div.objectmediareg').each(function() { $(this).objectLoad(); });
	$('div.objectmediabox').each(function() { $(this).objectLoad(); $(this).objectBox('boxmid'); });
	$('div.objecttxtalert').each(function() { $(this).objectLoad(); $(this).objectBox('boxalert'); });
	$('div.objecttxtmenu').each(function() { $(this).objectLoad(); $(this).objectTxtMenu(); $(this).objectBox('boxmax'); });
	$('div.col > div.rowobject').each(function() { $(this).objectMatch(); });
});	

jQuery.fn.objectLoad = function() { $(this).imgLoad(); $(this).parents('div.block').eq(0).fadeIn('fast'); }
jQuery.fn.objectClick = function() { $(this).find('div.item').each(function() { if ($(this).find('a').length == 1) { $(this).find('a').divClick($(this)); } }); }
jQuery.fn.objectBox = function($style) { 
	$(this).css({'background': 'transparent'}); 
	$(this).parents('div.block').eq(0).divBox($style, 'png');
	$(this).children('h1').headBox($style, 'png'); }
jQuery.fn.objectMatch = function() { 
	var $object = $(this).children('div.block').children('div.object'); 
	$object.matchHeight(); 
	$object.each(function() {
		if ($(this).is('.objecttxtticker')) { var $height = $(this).heightPlus() - $(this).children('h1').heightPlus('OUTER'); $(this).find('div.wrapgroup').cssHeight($height);  $(this).find('div.item').css({'height': $height + 'px', 'top': $height + 'px'});	 }
		if ($(this).siblings('div.boxmax').length) { $(this).objectBox('boxmax'); }
		else if ($(this).siblings('div.boxmid').length) { $(this).objectBox('boxmid'); }     });     }
jQuery.fn.objectTxtImg = function() { 
	if ($(this).parents('div.block1').length) { $(this).find('div.item').children('img.blob').imgResize(75, 75); }
	else if ($(this).parents('div.block3').length || $(this).parents('div.block4').length) { $(this).find('div.item').children('img.blob').imgResize(300, 300); }     }

//TXT MENU
jQuery.fn.objectTxtMenu = function() { 
	var $parent = $(this).parent('div.block').parent('div.col');
	if ($parent.hasClass('col1')) {
		var $height = $parent.parent('div.pagebody').heightPlus() - 30;
		if ($height > $parent.heightPlus()) { $(this).css({'height': $height + 'px'}); }     }     }

//TXT BOX
jQuery.fn.objectTxtBox = function() {
	$(this).objectTxtImg();
	if ($(this).parents('div.win').length && $(this).heightPlus() > 200) { $(this).css({height: (document.documentElement.clientHeight - 200) + 'px'}); }     }

//TXT BOOK	
jQuery.fn.objectTxtBook = function () {
	var $wrap = $(this).children('div.wrapgroup');
	$wrap.prepend('<div class="item"><h2>Click the right-hand page to turn</h2></div>');
	if ($wrap.children('div.item').length % 2) { $wrap.append('<div class="item"><h1>The End</h1><h2>Click here to start again</h2></div>'); }
	var $item = $wrap.children('div.item');
	$item.eq(0).prepend($wrap.siblings('h1'));
	$item.wrapInner('<div class="js"></div>');
	var $length = $item.length;
	var $width = ($wrap.widthPlus('INNER')) / 2 - 30;
	var $inner = $item.children('div.js');
	$inner.children('img').imgResize($width - 10, $width - 10);
	$item.css({'width': $width + 'px'});
	$item.matchSize();
	$inner.css({'width': $width + 'px'});
	$inner.matchHeight();
	$inner.each(function($key, $value) { $(this).append('<span class="min">' + $key + '</span>'); });
	var $itemleft = $wrap.children('div.item:nth-child(odd)');
	var $itemright = $wrap.children('div.item:nth-child(even)');
	$itemleft.css({'right': '50%'}); $itemleft.children('div.js').css({'float': 'right'});
	$itemright.css({'left': '50%'}); $itemright.children('div.js').css({'float': 'left'});
	var $height = $item.eq(0).heightPlus('INNER');
	$wrap.css({'height': $height + 'px'});
	$item.hideZindex();
	$inner.hide();
	$item.eq(0).showZindex(2);
	$item.eq(0).children('div.js').show();
	$item.eq(1).showZindex(2);
	$item.eq(1).children('div.js').show();
//action
	function action($pageclose, $pagehide, $pageopen, $pageshow) {
		$item.hide();
		$pageclose.showZindex(2);
		$pageshow.showZindex(1);
		$pageshow.children('div.js').show();
		$pageopen.css({zIndex: 2});
		$pagehide.showZindex(1);
		$pageclose.hideWidth(300);
		$pageclose.children('div.js').hideOpacity(300);
		$pageopen.delay(300).showWidth(300);
		$pageopen.children('div.js').delay(300).showOpacity(300, function() { $pageclose.hideZindex(); $pageclose.children('div.js').hide(); $pagehide.hideZindex(); $pagehide.children('div.js').hide(); });     }
//click
	$itemright.click(function() {
		var $this = $item.index(this);
		var $pageclose = $item.eq($this);
		var $pagehide = $item.eq($this - 1);
		if ($this >= $length - 1) { var $next = 0; } else { var $next = $this + 1; }
		var $pageopen = $item.eq($next);
		var $pageshow = $item.eq($next + 1);
		if ($length > 2) { action($pageclose, $pagehide, $pageopen, $pageshow); }     }); 
//click
	$itemleft.click(function() {
		var $this = $item.index(this);
		var $pageclose = $item.eq($this);
		var $pagehide = $item.eq($this + 1);
		var $pageopen = $item.eq($this - 1);
		var $pageshow = $item.eq($this - 2);
		if ($this != 0) { action($pageclose, $pagehide, $pageopen, $pageshow); }      });     }

//TXT CHANNEL
jQuery.fn.objectTxtChannel = function() {
	var $wrap = $(this).children('div.wrapgroup');
	$wrap.prepend('<ul class="menu menuleaf"><li class="other"><input class="button buttonnext" type="button" value="" /></li><li class="other"><input class="button buttonnone" type="button" value="" /></li><li class="other"><input class="button buttonprev" type="button" value="" /></li></ul>');
	var $prev = $wrap.find('input.buttonprev');
	var $none = $wrap.find('input.buttonnone');
	var $next = $wrap.find('input.buttonnext');
	var $ul = $wrap.children('ul.menu');
	var $item = $wrap.children('div.item');
	$(this).objectTxtImg();
	$item.matchHeight();
	var $length = $item.length;
	var $height = $item.eq(0).heightPlus('INNER');
	var $width = $item.eq(0).widthPlus('INNER');
	$item.each(function($key, $value) { 
		$(this).css({'left': ($width * $key) + 'px', 'position': 'absolute', 'top': 0});
		$ul.append('<li><input class="button buttonnum" type="button" value="' + ($key + 1) + '" /></li>'); });
	var $num = $ul.children('li').children('input.buttonnum');
	$num.eq(0).addClass('here');
	$ul.css({'margin-top': $height + 'px'});
	var $index = 0;
	$prev.click(function() { $index --; action(); });
	$next.click(function() { $index ++; action(); });
	$prev.hide();
	if ($length <= 1) { $next.hide(); }
	$num.click(function() { $index = parseInt($(this).val()) - 1; action(); });
	function action() {
		$item.each(function($key, $value) { $(this).animate({'left': (($width * $key) - ($index * $width)) + 'px'}, 'fast'); });
		if ($index == 0 || $index + 1 == $length) { $none.show(); } else { $none.hide(); }
		if ($index == 0) { $prev.hide(); } else { $prev.show(); }
		if ($index + 1 == $length) { $next.hide(); } else { $next.show(); }
		$num.removeClass('here');
		$num.eq($index).addClass('here');     }     }

//TXT TAB	
jQuery.fn.objectTxtTab = function () {
	$win = $(this).parents('div.win').length;
	if ($win) { $(this).parents('div.win').show(); }
	$(this).find('div.item').wrapAll('<dl class="menu menutab"></dl>');
	$(this).find('div.item').each(function($key, $value) { 
		var $h1 = $(this).find('h1:eq(0)');
		if ($h1.length > 0) { var $title = $h1.html(); $h1.remove(); }
		else { var $title = 'Page ' + ($key + 1); }
		$(this).after('<dt>' + $title + '</dt><dd><div class="item">' + $(this).html() + '</div></dd>');
		$(this).empty().remove(); });
	var $dl = $(this).find('dl.menutab');
	var $dt = $dl.children('dt');
	var $dd = $dl.children('dd');
	$(this).objectTxtImg();
	$dt.eq(0).addClass('here');
	if ($win) { $dd.css({height: (document.documentElement.clientHeight - 200) + 'px'}); }
	else { $dd.matchHeight(); }
	$dl.height($dd.eq(0).heightPlus('POS'));
	$dd.hide();
	$dd.eq(0).show();
	$(this).show();
	if ($win) { $(this).parents('div.win').hide(); }
	$dt.click(function() {
		if ($(this).attr('class') != 'here') { 
			$(this).siblings('dd').css({zIndex: 0}).fadeOut('fast');
			$(this).siblings('dt').css({zIndex: 0}).removeClass('here');
			$(this).next('dd').css({zIndex: 1}).fadeIn('fast');
			$(this).css({zIndex: 2}).addClass('here'); }     });     }
			
//TXT TICKER
jQuery.fn.objectTxtTicker = function($time) {
	var $wrap = $(this).children('div.wrapgroup');
	var $item = $wrap.children('div.item');
	$(this).objectTxtImg();
	$item.matchSize();
	var $height = $item.eq(0).heightPlus('INNER');
	$wrap.css({'height': $height + 'px'});
	$item.css({'top': $height + 'px'});	
	$item.mouseover(function() { $item.stop(true, false); });
	$item.mouseout(function() { action(); });
	action();
	function action() {
		var $height = $item.eq(0).heightPlus('INNER');
		var $current = $wrap.children('div.item').eq(0);
		var $top = parseInt($current.css('top'));
		if ($top == 0) { var $speed = ($height + $top) / $time; $current.delay(2000).animate({'top': -$height}, $speed, function() { $current.appendTo($wrap); $current.css({'top': $height + 'px'}); action(); }); }
		else if ($top < 0) { var $speed = ($height + $top) / $time; $current.animate({'top': -$height}, $speed, function() { $current.appendTo($wrap); $current.css({'top': $height + 'px'}); action(); }); }
		else { var $speed = $top / $time; $current.animate({'top': 0}, $speed, function() { action(); }); }     }     }
		
//IMG		
//IMG BOX
jQuery.fn.objectImgBox = function() { if ($(this).parents('div.block1').length) { $(this).find('div.item').children('img.blob').imgSquare(); }  }	
		
//IMG GALLERY
jQuery.fn.objectImgGallery = function($size) {
	if ($(this).parents('div.block1').length) { var $position = 'bottom'; $size -= 5; } 
	else if ($(this).parents('div.block2').length) { var $position = 'bottom'; }
	else { var $position = 'left'; }
	var $wrap = $(this).children('div.wrapgroup');
	var $item = $wrap.children('div.item');
	var $first = $item.eq(0);
	var $img = $item.children('img.blob');
//menu
	$wrap.append('<ul class="menu"></ul>');
	var $ul = $wrap.children('ul.menu');
	$img.each(function($key, $value) { $ul.append('<li></li>'); $(this).clone().appendTo($ul.children('li').eq($key)); });
	var $thumb = $ul.children('li').children('img');
	$thumb.imgResize($size, $size);
	$thumb.imgSquare();
//item
	$img.imgMatch();
	$item.matchHeight();
	var $height = $first.heightPlus('INNER');
	var $width = $wrap.widthPlus('INNER') - $first.widthPlus('INNER');
	$item.hide();
	$first.show();
	$thumb.eq(0).addClass('here');
//position
	if ($position == 'left') { $wrap.css({'height': $height + 'px'}); $ul.css({'width': $width + 'px'}); }	
	else if ($position == 'bottom') { $wrap.css({'padding-top': $height + 'px'}); }
//action
	$thumb.click(function() {
		var $index = $ul.children('li').children('img').index(this);
		var $item = $wrap.children('div.item');
		if ($item.eq($index).is(':hidden')) {
			$item.fadeOut('fast');
			$item.eq($index).fadeIn('fast');
			$thumb.removeClass('here');
			$(this).addClass('here'); } });     }

//IMG THUMB
jQuery.fn.objectImgThumb = function() {
	if ($(this).parents('div.block1').length) { var $size = 50; } 
	else if ($(this).parents('div.block2').length) { var $size = 130; } 
	else if ($(this).parents('div.block3').length) { var $size = 95; }
	else if ($(this).parents('div.block4').length) { var $size = 135; }
	var $item = $(this).children('div.wrapgroup').children('div.item');
	var $img = $item.children('img.blob');
	$img.imgResize($size, $size);
	$img.imgSquare();
	$item.css({width: $img.widthPlus('BOX') + 'px'});     }


//IMG POPUP
jQuery.fn.objectImgPopup = function() {
//resize
	if ($(this).parents('div.block1').length) { var $size = 50; }
	else if ($(this).parents('div.block2').length) { var $size = 130; } 
	else if ($(this).parents('div.block3').length) { var $size = 95; }
	else if ($(this).parents('div.block4').length) { var $size = 135; }
	var $item = $(this).children('div.wrapgroup').children('div.item');
	$id = $('div.objectimgpopup').index(this);
	var $thumb = $item.children('img'); //blob min
	$thumb.imgResize($size, $size);
	$thumb.imgSquare();
//win
	$.winAdd('imgpopup_' + $id, 2, 'Images', 'HIDE');
	var $win = $('div#imgpopup_' + $id);
	var $winobject = $win.find('div.object');
	var $winwrap = $winobject.find('div.wrapgroup');
//clone
	$item.each(function($key, $value) { 
		$(this).clone().appendTo($winwrap);
		var $clone = $winwrap.children('div.item:eq(' + $key + ')');
		var $img = $clone.children('img.blob');
		$clone.imgMax($img.attr('src').replace('/min/','/max/'), $img.attr('class'));
		$img.remove(); });
	$item.css({width: $thumb.widthPlus('BOX') + 'px'});
//clone
	var $clone  = $win.find('div.item');
	$clone.css({position: 'absolute', top: 0, left: 0}); 
	var $length = $clone.length;
	var $first = $clone.eq(0);
	var $img = $clone.children('img.blob');
	$clone.matchHeight();
	$winwrap.css({height: $first.heightPlus('BOX') + 'px'});
	$winobject.append('<ul class="menu menuleaf"><li class="other"><input class="button buttonnext" type="button" value="Next" /></li><li class="other"><input class="button buttonnone" type="button" value="" /></li><li class="other"><input class="button buttonprev" type="button" value="Prev" /></li></ul>');
	var $prev = $winobject.find('input.buttonprev');
	var $none = $winobject.find('input.buttonnone');
	var $next = $winobject.find('input.buttonnext');
	var $index = 0;
	$clone.hide();
	$win.winBox(); 
//action	
	$prev.click(function() { $index --; action(); });
	$next.click(function() { $index ++; action(); });
	$thumb.click(function() { $index = $thumb.index(this); $win.winShow('', ''); action(); });
	$win.find('input.button[value="close"]').click(function() { $clone.fadeOut('fast'); });
	function action() { 
		$clone.fadeOut('fast');
		$clone.eq($index).fadeIn('fast');
		if ($index == 0 || $index + 1 == $length) { $none.show(); } else { $none.hide(); }
		if ($index == 0) { $prev.hide(); } else { $prev.show(); }
		if ($index + 1 == $length) { $next.hide(); } else { $next.show(); }     }     }
	
//IMG TICKER
jQuery.fn.objectImgTicker = function($time) {
	var $wrap = $(this).children('div.wrapgroup');
	var $item = $wrap.children('div.item');
	$item.children('img.blob').imgMatch();
	$item.matchHeight();
	$wrap.css({'height': $item.eq(0).heightPlus() + 'px'});
	$item.hideZindex();
	$item.eq(0).showZindex(1);
	if ($item.length > 1) { setTimeout(action, $time); }
//action
	function action() {
		var $current = $wrap.children('div.item:eq(0)');
		var $next = $wrap.children('div.item:eq(1)');
		$current.fadeOut('slow');
		$next.fadeIn('slow', function() { $next.showZindex(1); $current.hideZindex(); $current.appendTo($wrap); setTimeout(action, $time); });     }      }
