function ShowBubble(msg){ // shows invitation
	 $("body").append("<div id='screen'><a href='javascript:void(0)'></a></div>");
    $("body").append("<div id='lightbox'></div>").show();
	 $("#lightbox").append(msg);
	 $("body").append("<iframe id='lightiframe' src='javascript:void(0);' marginwidth='0' marginheight='0' align='bottom' scrolling='no' frameborder='0'></iframe>");
    $('#screen').css('height', getyScroll());
	 $('#screen a, #lightbox a.jHelperTipClose').bind('click', HideBubble); 
	 scrl = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body && document.body.scrollTop ? document.body && document.body.scrollTop : 0;
	 $("#lightbox").css('top', scrl + 30); // centered = screen.availHeight/2 - $("#lightbox").height()
	 $("#lightiframe").css('top', $("#lightbox").css('top'));
	 $("#lightiframe").css('left', $("#lightbox").css('left'));
	 $("#lightiframe").css('margin-left', $("#lightbox").css('margin-left'));
 	 $("#lightiframe").width($("#lightbox").width());
	 $("#lightiframe").height($("#lightbox").height());
	 if ($.browser.msie && parseInt($.browser.version) <= 6){
	    $(document).pngFix();
	 }    
    return false;
}

function HideBubble(){ // hides invitation
    $('#screen').remove();
	 $("#lightbox").remove();
    $("#lightiframe").remove();
	 
    return false;
}

function getyScroll(){ // calculates screen hight
      yScroll = 0;

      if (window.innerHeight && window.scrollMaxY){
        yScroll = window.innerHeight + window.scrollMaxY;

        var deff = document.documentElement;
        var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;

        yScroll -= (window.innerHeight - hff);
      } 
      else if (document.body.scrollHeight > document.body.offsetHeight){
        // all but Explorer Mac
        yScroll = document.body.scrollHeight;
      } 
      else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        yScroll = document.body.offsetHeight;
      }

      return yScroll;
}      
$(document).ready(function(){
	$(".light").click(function(){
		var relmatch = this.rel.match(/info\[(.+)\]/);
		if(relmatch) var key = relmatch[1];
		else return false;
		$.ajax({
			url: '/server/ajax/pophelp.php',
			data: 'key='+key,
			async: false,
			success: ShowBubble
		});
	});
	
	$(".popup").each(function(){ // Popup help function
		var relmatch = this.rel.match(/info\[(.+)\]/);
		if(relmatch) var key = relmatch[1];
		else return;
		$(this).jHelperTip({
			trigger: "click",
			source: "ajax",
			type: "GET", 
			url: '/server/ajax/pophelp.php',
			data: 'key='+key,
			loadingImg: '_resource/_image/_gif/loader.gif',
			loadingText: 'loading...',
			autoClose: true, 
			opacity: 1
		});
	});
});

function limitText(limitField, limitCount, limitNum) { // Limits characters
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function clear_textbox(){ // Clear Text Box
	if (document.forms['searchform'].search.value == "Find product, designer or articles...")
		document.forms['searchform'].search.value = "";
}

function showhide(id){
	if (document.getElementById){
		obj = document.getElementById(id);
		if (obj.style.display == "none"){
			obj.style.display = "";
		} else {
			obj.style.display = "none";
		}
	}
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=550');");
	}

$(document).ready(function() {
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}

	var config = {    
		 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#navBar li .sub").css({'opacity':'0'});
	$("ul#navBar li").hoverIntent(config);
});


$(document).ready(function(){
	$("#hpBanner > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 10000, true);
});
