/*
 * @version 1.0 by Sofresh Inc.
 */


(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
 
 
 
 
 
var closeSubNav;
var onSubNav = false;
$(document).ready(function(){
	
	//////////////////////
	// Gobal function	//
	//////////////////////
	
	//	Replace VNJikharev
	Cufon.replace('.jikharev');
	
	//	Remove divider for last navigation item
	$('.nav li:last').css('background','none');
	$('.navSub').find('li:last').each(function(){ $(this).css('background','none');});

	//	Setup Subnavigation	
	$('.nav a').hover(
		function(){
			$(this).stop(true, true).animate({ backgroundPosition: "0 100%"});
		},
		function(){
			$(this).not('.active').stop(true, true).animate({ backgroundPosition: "0 0%"});
		}
	);
	
	//$('.nav').mouseover(function(){ onSubNav = true; });
	$('.searchTop, .ct').mouseover(function(){ $('.nav_sub_bg').slideUp(500, 'easeOutQuart'); });
	/*$('.nav_sub_bg').hover(function(){
		onSubNav = true;
	},
	function(){
		onSubNav = false;
	});	*/
	
//	$('ul#nav > li').hover(function() {		
//		if ($(this).attr('class') != "s"){
//			$('.nav_sub_bg').stop(true,true).slideUp(500, 'easeOutQuart');			
//		}
//		else{
//			$('.nav_sub_bg').stop(true,true).slideDown(1000, 'easeOutQuart');
//		}
//									
//		$('a:first', this).addClass('hover');
//										
//		//$('ul:first', this).stop(true,true).fadeIn(1500);
//		if (onSubNav == true) {
//			$('ul:first', this).stop(true,true).slideDown(600);
//		}
//		else{
//			$('ul:first', this).stop(true,true).delay(200).slideDown(1000);			
//		}
//		//$('ul:first', this).show();
//	},
//	function() {
//		//if (onSubNav == true) $('.nav_sub_bg').stop(true,true).slideUp(1000, 'easeOutQuart');
//		//closeSubNav =  setTimeout("$('.nav_sub_bg').stop(true,true).slideUp(1000, 'easeOutQuart')", 5000);
//		
//		$('a:first', this).removeClass('hover');		
//		//$('ul:first', this).stop(true,true).slideUp(300);
//		//$('ul:first', this).stop(true,true).delay(200).slideUp(600);
//		$('ul:first', this).stop(true,true).hide();
//		
//	});		
	
	
	var year_footer = new Date();
	$('#currentYear').html(year_footer.getFullYear());
	
	
	
	//////////////////////
	// Home				//
	//////////////////////
	
	if ($('#section_home').html() != null){
	
		// remove background for last item at bottom list
		$('.bt li:last').css('background','none');
		
		// masterShow
		//init_masterImg();
		
		var flashvars = {};
		var params = { wmode:"transparent", allowScriptAccess:"always", menu:"false"};
		var attributes = {};
		swfobject.embedSWF("main.swf", "home-masterShow", "1033", "442", "9.0.0","swf/expressInstall.swf", flashvars, params, attributes);
	}
	
	
	//////////////////////
	// Brands			//
	//////////////////////
	
	if ($('#section_brand').html() != null){
		
		// remove background for last item at bottom list
		$('.bt li:last').css('background','none');
		
		// masterShow
		init_masterImg_brand();
	}
	
	
	
	///////////////////
	// NEWS			 //
	///////////////////
	
	if ($('#section_news').html()!=null){
		$('.news_item').append('<p class="news_overlay"></p>');
		$('.news_overlay').fadeTo("slow", 0.9);
		
		$('.news_item').hover(
			function(){
				$(this).addClass('newsOver');
				$(this).find('.news_tit').stop().animate({ bottom:"-60px"});
				$(this).find('.news_overlay').stop().animate({ height:"218px", backgroundColor:"#fff", opacity:"0.8"}, 200, "linear", 
					function(){
						$('.newsOver .news_tit_over').fadeIn('normal');
					});				
			},		
			function(){
				$('.newsOver .news_tit_over').hide();
				$('.newsOver').removeClass('newsOver');
				$(this).find('.news_tit').stop().animate({ bottom:"0"});
				$(this).find('.news_overlay').stop().animate({ height:"60px", backgroundColor:"#fff", opacity:"0.9"}, 200, "linear")			
			}
		);
	}
	
	
	
	///////////////////
	// CAREERS		 //
	///////////////////
	
	if ($('#section_career').html()!=null){
		$('.vacancy_item a').not('.btn_apply').toggle(
			function(){
				$(this).next().slideDown();
			},
			function(){
				$(this).next().slideUp();
			}
		);
		
		initTip();
	}
	
});





//////////////////////////////////
// HOME // masterShow slideshow
//////////////////////////////////

var masterShow_length;
var masterShow_auto;
function init_masterImg(){
	
	// Adding white overlay & buttons
	$('.masterShow').append('<a href="#" class="b_btn_prev" onclick="return false"></a><a href="#" class="b_btn_next" onclick="return false"></a>');
	/*$('.masterShow_item').each(function(){
		$(this).append('<p class="masterShow_whitoverlay"></p>');
	});*/
	
	
	masterShow_length = $('.masterShow_item').length;
	if (masterShow_length<2){
		$('.b_btn_prev, .b_btn_next').css("visibility","hidden");
		$('.masterShow_item:first').addClass('masterShow_show');		
	}
	else{		
		$('.masterShow_item').each( function(i){
			$(this).attr('rel',i)/*.css({zIndex:i})*/;
		});		
		$('.masterShow_item:first').addClass('masterShow_show');
		$('.masterShow_item:first h3, .masterShow_item:first .btn_learnmore, .masterShow_item:first .product_thumb').show();
		//$('.masterShow').append('<div class="masterShow_disable"></div>');
		
		// Button init event
		$('.b_btn_prev').live("click", masterShow_prev);
		$('.b_btn_next').live("click", masterShow_next);
		
		masterShow_auto =  setTimeout("masterShow_next()",4000);
	}	
}

function masterShow_liveButton(){
	$('.b_btn_prev').live("click", masterShow_prev);
	$('.b_btn_next').live("click", masterShow_next);
}
function masterShow_dieButton(){
	$('.b_btn_prev').die("click", masterShow_prev);
	$('.b_btn_next').die("click", masterShow_next);
}

function masterShow_prev(){
	if (masterShow_auto) clearTimeout(masterShow_auto);
	
	//$('.masterShow_disable').show();
	masterShow_dieButton();
	
	currentItem = $('.masterShow_show').attr('rel');
	currentItem = Number(currentItem)-1;
	
	if (currentItem<0) currentItem=masterShow_length-1;
//	$('.masterShow_item:eq('+currentItem+')').addClass('masterShow_prev').css("left","-955px");
	
//	$('.masterShow_show').stop().animate({left:"955px"}, 1500,  function(){ $(this).removeClass('masterShow_show'); })
//	$('.masterShow_prev').stop().animate({left:"0px"}, 1500,  function(){
//	$(this).removeClass('masterShow_prev').addClass('masterShow_show');
//		//$('.masterShow_disable').hide();
//		masterShow_liveButton();
//	})
	
	
	$('.masterShow_show').fadeOut(2000, function(){ $(this).removeClass('masterShow_show'); });
	$('.masterShow_item:eq('+currentItem+')').addClass('masterShow_prev').fadeIn(2000, function(){
																								
		$(this).removeClass('masterShow_next').addClass('masterShow_show');		
		
		if ($('#section_brand').html() != null){
			//$('.masterShow_item:eq('+currentItem+')').find('h3').fadeIn(1000, function(){});
			$('.masterShow_item:eq('+currentItem+')').find('.btn_learnmore').fadeIn(1000, function(){	
				$('.masterShow_item:eq('+currentItem+')').find('.product_thumb').fadeIn(1000, function(){	
					masterShow_liveButton();
				});
			});
		}
		else masterShow_liveButton();
		
	});
	
	if ($('.brand_callact').html() != null){
		$('.brand_callact a').removeClass('active');
		$('.brand_callact a:eq('+currentItem+')').addClass('active');
	}
	
	masterShow_auto =  setTimeout("masterShow_next()",7000);
	return false;
}

function masterShow_next(){	
			
	if (masterShow_auto) clearTimeout(masterShow_auto);

	//$('.masterShow_disable').show();
	masterShow_dieButton();
	
	currentItem = $('.masterShow_show').attr('rel');
	currentItem = Number(currentItem)+1;
	
	if (currentItem==masterShow_length) currentItem=0;
//	$('.masterShow_item:eq('+currentItem+')').addClass('masterShow_next').css("left","955px");
//	
//	$('.masterShow_show').stop().animate({left:"-955px"}, 1500,  function(){ $(this).removeClass('masterShow_show'); })
//	$('.masterShow_next').stop().animate({left:"0px"}, 1500,  function(){
//		$(this).removeClass('masterShow_next').addClass('masterShow_show');
//		//$('.masterShow_disable').hide();
//		masterShow_liveButton();
//	})

	$('.masterShow_show').fadeOut(2000, function(){ $(this).removeClass('masterShow_show'); });
	$('.masterShow_item h3, .masterShow_item .btn_learnmore, .masterShow_item .product_thumb').hide();
	
	$('.masterShow_item:eq('+currentItem+')').addClass('masterShow_next').fadeIn(2000, function(){
																								
		$(this).removeClass('masterShow_next').addClass('masterShow_show');		
		
		if ($('#section_brand').html() != null){
			//$('.masterShow_item:eq('+currentItem+')').find('h3').fadeIn(1000, function(){});
			$('.masterShow_item:eq('+currentItem+')').find('.btn_learnmore').fadeIn(1000, function(){	
				$('.masterShow_item:eq('+currentItem+')').find('.product_thumb').fadeIn(1000, function(){	
					masterShow_liveButton();
				});
			});
		}
		else masterShow_liveButton();
	});
	
	if ($('.brand_callact').html() != null){
		$('.brand_callact a').removeClass('active');
		$('.brand_callact a:eq('+currentItem+')').addClass('active');
	}
		
	masterShow_auto =  setTimeout("masterShow_next()",7000);
	return false;
}




var masterShow_length;
function init_masterImg_brand(){
	
	// Adding white overlay & buttons
	$('.masterShow').append('<a href="#" class="b_btn_prev" onclick="return false"></a><a href="#" class="b_btn_next" onclick="return false"></a>');	
	
	masterShow_length = $('.masterShow_item').length;
	if (masterShow_length<2){
		$('.b_btn_prev, .b_btn_next').css("visibility","hidden");
	}
	else{		
		$('.masterShow_item').each( function(i){
			$(this).attr('rel',i);
		});
			
		if ($('#masterShow_activeItem').html() != null) $('#masterShow_activeItem').addClass('masterShow_show');
		else $('.masterShow_item:first').addClass('masterShow_show');
		//$('.masterShow').append('<div class="masterShow_disable"></div>');
		
		$('.masterShow_show p, .masterShow_show .product_thumb').show();
		//$('.brand_callact a:first').addClass('active');
		
		
		// Button init event
		$('.b_btn_prev').live("click", masterShow_prev);
		$('.b_btn_next').live("click", masterShow_next);	
		
		masterShow_auto =  setTimeout("masterShow_next()",4000);
	}
	
}

function brandShow(selectedBrand){
	
	$('.disable_callact').show();
	// Brand
	if ($('.brand_callact').html() != null){
		$('.brand_callact a').removeClass('active');
		$('.brand_callact a:eq('+selectedBrand+')').addClass('active');
	}

	if (masterShow_auto) clearTimeout(masterShow_auto);
	
	currentItem = selectedBrand;
	
	$('.masterShow_show').fadeOut(2000, function(){ $(this).removeClass('masterShow_show'); });	
	$('.masterShow_item:eq('+selectedBrand+')').addClass('masterShow_next').fadeIn(2000, function(){
																								
		$(this).removeClass('masterShow_next').addClass('masterShow_show');		
		
		$('.masterShow_item:eq('+selectedBrand+')').find('.btn_learnmore').fadeIn(1000, function(){	
			$('.masterShow_item:eq('+selectedBrand+')').find('.product_thumb').fadeIn(1000, function(){	
				$('.disable_callact').hide();
			});
		});
		
	});
	
	currentItem = Number(currentItem)+1;
	masterShow_auto =  setTimeout("masterShow_next()",5000);
}



/*
 * Lightbox use jQuery library - Require $ 1.2+
 * @Version:	1.0.5
 * History: 	[05/19] update caobox position with pagescroll

Usage: 	caobox.show('boxID', 'overlayColor', 'overlayOpacity', 'overlayDisable', 'leftPosition', 'topPosition')
Exp:	caobox.show('testID', '000', '50', '', '10', '10')
Arguments:
	divID : [char] Div’s id
	overlayColor : [hex number] Used to define the overlay background color.  ‘000‘ (black) is default
	overlayOpacity : [int 0~100] Used to define the overlay opacity. ‘50‘ is default.
	overlayDisable : ['false'] Used to disable click on overlay to close popup. null is default
	leftPosition : [int] The padding CSS information used in the left position of image box. null mean center is default. [int]<0 is padding-right position
	topPosition : [int] The padding CSS information used in the top position of image box. null mean middle is default. [int]<0 is padding-bottom position
*/

var inner_boxID ;
var cloneTemp;
var caobox = {		
	fadeEffectDuration : 0,
	fade:"#fade",
	light:"#light",
	boxID:"",
	overlayBgColor:"#000000",
	overlayOpacity:"50",
	
	show:function(boxId, callback)
	{
		/*$("*", document.body).click(function (e) {
		  var offset = $(this).offset();
		  e.stopPropagation();
			currentOffsetTop = offset.top;
		});*/
		
		/*var offset = getCurrentOffset.offset();
		e.stopPropagation();
		alert(offset.top);*/
		
		
		// Get layer Background color & opacity
		//if (overlayBgColor) this.overlayBgColor = "#"+ overlayBgColor;
		//if (overlayOpacity) this.overlayOpacity = overlayOpacity;
		
		// Add layer
		if ($('#light').html() == null){
			$('body').prepend('<div id="light"></div><div id="fade"></div>');
		}
		$('#light, #fade').css('display','none');
		$('#light').css({	'position':'absolute',
							'zIndex':'10002',
							'height':'auto'/*, 'overflow':'hidden'*/});
		$('#fade').css({	'position':'absolute',
					   		'zIndex':'10001',
					   		'left':'0',
							'top':'0',
					   		'backgroundColor': ''+ this.overlayBgColor +'',
					   		'opacity':'.'+ this.overlayOpacity+'',
							'filter':'alpha(opacity='+ this.overlayOpacity +')'
						}).click(	function(){
										//if (overlayDisable) return true;
										//else caobox.hide();
									});
	
		// Show layer
		this.boxID='#'+boxId;		
		$('object, embed, select').css('visibility','hidden');
		$('object, embed').css('display','none');

		
		var autodectect = boxId.substring(boxId.length-3, boxId.length);
		
		// Auto dectect Ajax loading
		if ((autodectect=="tml")||(autodectect=="php")){
			$(this.light).load(boxId, function(response, status, xhr) {
			  if (status == "error") {
				var msg = "Sorry but there was an error: ";
				$("#error").html(msg + xhr.status + " " + xhr.statusText);
			  }
			});
		}
		else{		
			//inner_boxID = $(this.boxID).html();
			var oClone = $(this.boxID).clone();
			$(this.boxID).remove();
			$(this.boxID+'_hidden').remove();
			oClone.appendTo($(this.light));
			//cloneTemp = $(this.boxID).parent().clone().html();
			
			//$(this.light).append(cloneTemp);

			//if (
			//$(this.boxID).parent().siblings().find('.lightbox').attr('id');
			
			//$('.lightbox:last').html('');
			
			
			/*if (boxId) var filetype = inner_boxID.substring(inner_boxID.length-3, inner_boxID.length);*/
		// FLV		
		//		if (filetype == "flv"){
		//			var embedFLV = '<object height="400" width="420" type="application/x-shockwave-flash" data="'+inner_boxID+'&bufferTime=3&autoStart=false">'
		//				+'<param value="true" name="allowfullscreen"/>'
		//				+'<param value="high" name="quality"/>'
		//				+'<param value="'+inner_boxID+'" name="src"/></object>';		
		//			var full_boxID = "<div id="+ boxId +">"+ embedFLV +"</div>";
		//			$(this.light).append(full_boxID);
		//		}
		//		else{
		//			$(this.boxID).clone().appendTo($(this.light));
		//		}
		}
		
		//$(this.boxID).show();
		//$(this.light).fadeIn('slow', function(){
			 //$(this.light).css({display:'block'}); 
		//});
		
		
		//$(this.light).fadeIn( this.fadeEffectDuration, function(){	
		$(this.light).slideDown('0', function(){		
			//callback
			if (callback){
				var callbackFunction = callback;
				window[callbackFunction]();				
			}
		});
		

		//var _top = Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		
	// Left position, default is center
		//_left = Math.round(getDocumentSize(2) - $(this.light).width());
		_left = Math.round((getDocumentSize(2) - 480) / 2);			
		//$(this.light).css({left: _left+ "px"});

		/*_left = Math.round((getDocumentSize(2) - $(this.light).width())/2);*/
		
	// Top position, default is middle
		//var offset = $(getCurrentOffset).parent().offset();
		//_top = offset.top - 150;
		//$(this.light).css({top: _top+ "px"});
		$(this.light).css({	top:getPageScroll()[1] + (getPageHeight() / 10),
							left: _left+ "px" });
		

		
		
		
		//$(this.light).css({left: _left});
		//$(this.light).css({top: _top});
		
		$('#light object, #light embed, #light select').css({visibility:"visible", display:"block"});
		caobox.showAlertLayer();
		
		//alert($('.lightbox').attr('id'));
		//$('body').children().find('#'+boxId).html('');
		
		//caobox.setFocusElement();
		//window.scrollTo(0,0);
		window.onresize=caobox.resizeLayers;
	},
	
	hide:function(){
		//$(this.fade).fadeOut(this.fadeEffectDuration);
		$(this.fade).hide();
		
		//$(this.light).fadeOut(this.fadeEffectDuration, function(){
		$(this.light).hide(function(){
			$('object, embed, select').css('visibility','visible');
			$('object, embed, select').css('display','');
			$('#fade, #light').remove();
			
		});
		
		var lightboxID = $(this.boxID).attr('id');
		$('#'+lightboxID+':last').html(inner_boxID);		
		returnBoxID = $('.lightbox').attr('id');
		var oClone = $(this.boxID).clone();
		$('#light').remove();
		var boxhidden = this.boxID.substr(1)+'_hidden';
		$('body').append('<div id="'+boxhidden+'" style="display: none;"></div>');
		oClone.appendTo($('#'+boxhidden));
		
		
		
/*		cloneTemp = $(this.boxID).parent().html();
		$(this.boxID).parent().html('');
		$('body').append('<div style="display:none">'+cloneTemp+'</div>');
*/		
		
		
	},
	
	showAlertLayer : function(){
		var _height=getDocumentSize(1);
		var _width =getDocumentSize(0);
		
		if(_width < 974) 
			 _width = 974;	
		
		if($(this.boxID).height() > getDocumentSize(1))
			_height=parseInt($(this.boxID).height()) + 65;		
		
		$(this.fade).css({width:_width +'px'});
		$(this.fade).css({height:_height +'px'});	
		
		//$(this.fade).css({display:'block'}); 
		//$(this.fade).fadeIn( this.fadeEffectDuration);
		$(this.fade).show();
	},
	
	resizeLayers : function(){
		if($(this.boxID).height() > getDocumentSize(1)){
			var _height = parseInt($(this.boxID).height());
			var pageHeight = _height;
		}
		else{
			if (getDocumentSize(1) > getDocumentSize(3)){ var pageHeight=getDocumentSize(1)}
			else{ var pageHeight=getDocumentSize(3);}
		};
		
		if(getDocumentSize(0) < 974) $('#fade').css({width:974 + "px"});
		else $('#fade').css({width:getDocumentSize(0) + "px"});
		$('#fade').css({height:pageHeight + 'px'});
		$('#light').css({left: Math.round((getDocumentSize(2) - $('#light').width()) / 2)+"px"});
		
		var _top=Math.round((getDocumentSize(3) - $(this.light).height()) / 2);
		if(_top < 0) _top = 20;
		$(this.light).css({top:_top+"px"});
	},
	
	findFucusElement:function(){
		$("#light").find('object, embed, select').css({'visibility':'visible'});
		$("#light").find('input[@type!=hidden], a, select, textarea').addClass('setFocusAble');			
		return $('.setFocusAble');
	},
	
	setFocusElement:function(){
		var i = 0;
		var cntElement = 0;	
		var allFocusElement = caobox.findFucusElement();
		var len=allFocusElement.length;	
		
		if (len>0){
			for(var temJ = 0; temJ<len-1; temJ++){
				$(allFocusElement[temJ]).attr('rel',temJ+1);
			}
			
			// fix focus on 1st hidden element
			if ( allFocusElement[0].style.display == 'none') 
				allFocusElement[1].focus();
			else
				allFocusElement[0].focus();
	
	
			allFocusElement.focus(function(){ cntElement=this.getAttribute('rel'); });
			$("#light").keydown(function(event){									 
				if(event.shiftKey){
					if(event.keyCode == 9){					
						if (i!=cntElement) i=cntElement;
						i--;			
						if (i == 0) {
							i = len-1;
							allFocusElement[i].focus();
							return false;
						}
					}
				}
				else{
					if(event.keyCode == 9){
						if (i != cntElement) i = cntElement;
						if (i == len-1){
							i=0;
							allFocusElement[0].focus();						
							return false;
						}
						else{
							i++;
						}
					}
				}			
			}); 
		}
	},
	
	unbindClickFace:function(){
		$(this.fade).unbind('click');
	},
	
	init:function()
	{		
		$(document).ready(function(){
			$('.caobox-popup').hide();
			$('body').css({'margin':'0', 'padding':'0'}); // hack browser
			$('img.caobox-popup').css({ 'border':'5px solid #000'});
		})		
	}
};
caobox.init({							
});

// Get ducument size
// @param int 0 ~ 3
// @return array [width of current page] [height of current page] [width of window] [height of window]
function getDocumentSize(val){
	var xScroll,yScroll,value;
	
	if(window.innerHeight&&window.scrollMaxY){
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight){
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
		}
		else{
			xScroll=document.body.offsetWidth;
			yScroll=document.body.offsetHeight;
		}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;
			windowHeight=document.documentElement.clientHeight;
		}
		else if(document.body){
			windowWidth=document.body.clientWidth;
			windowHeight=document.body.clientHeight;
		}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize[val];
};

function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }

  // Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
}


/* Tooltip */
var dom = (document.getElementById) ? true : false;
var ns5 = (!document.all && dom || window.opera) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var _ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !_ie4 && !ie5 && !dom) ? true : false;
var origWidth, origHeight;
if (nodyn) { event = "nope" }
var tipFollowMouse= true;	
var offX= 0;
var offY= -38; 
var tooltip, tipcss;
var blast_txt;
function initTip() {
	if (nodyn) return;
	tooltip = (_ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
	tipcss = tooltip.style;	
	
	if (tooltip&&tipFollowMouse) {
		document.onmousemove = trackMouse;
	}
}
var t1,t2;
var tipOn = false;
function doTooltip(evt, value) {
	//if(tipcss) tipcss.display='block';
	if (tipcss) $('#tipDiv').stop(true, true).fadeIn('400');
	if (!tooltip) return;
	if (t1) clearTimeout(t1);	if (t2) clearTimeout(t2);
	tipOn = true;	
	
	if (_ie4||ie5||ns5) {
		var tip ="<div class='tooltip'>" + value + "</div>";
	 	tooltip.innerHTML = tip;
	}
	if (!tipFollowMouse) positionTip(evt);
	else t1=setTimeout("tipcss.visibility='visible'",100);	
}
var mouseX, mouseY;
function trackMouse(evt) {
	standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
	mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;
	if (tipOn) positionTip(evt);
}
function positionTip(evt) {
	if (!tipFollowMouse) {
		standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
		mouseX = (ns5)? evt.pageX: window.event.clientX + standardbody.scrollLeft;
		mouseY = (ns5)? evt.pageY: window.event.clientY + standardbody.scrollTop;		
	}
	var tpWd = (_ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
	var tpHt = (_ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
	var winWd = (ns5)? window.innerWidth+window.pageXOffset: standardbody.clientWidth+standardbody.scrollLeft;
	var winHt = (ns5)? window.innerHeight+window.pageYOffset: standardbody.clientHeight+standardbody.scrollTop;
	var arrowcss = document.getElementById('arrow');
		
		tipcss.left = mouseX+offX+"px";
		offX= -23;

	tipcss.top = mouseY+offY+"px";			

	if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);
}
function hideTip() {
	if (!tooltip) return;
	//t2=setTimeout("tipcss.display='none'",100);
	$('#tipDiv').hide();
	tipOn = false;
}
document.write('<div id="tipDiv"></div>')






