$(document).ready(function() {
	addIEClass();
	$("#footerBottom li:first").css("background","none");
	$(".topLinks li:first").css("background","none");
    smallHeader();
	homeBannerCycle();
	homeBannerCycle2();
    skinTableContent();
	rightMenu();
	ajustementFooter();
    adjustRowHeight();
	applyWatermark();
	$("#bottomBanners").each(function(){
		$(".bottomBannersBlock:odd").addClass("secondBlock");	
	})
	$("#productSearchResults #productResultsTable tr").each(
		function(){
			$(this).find("TD:last").addClass("TDLast");
		}
	)
	
});

function smallHeader(){
	if( $("#banner").children().size() == 0 && $("#tabMenu").children().size() == 0){
		$("#page").addClass("pageGeneralContent");
	}
}

function homeBannerCycle(){
	$(function() { 
		$('#bannerAnimation').cycle({ 
			fx:     'fade', 
			speed:  2000,
			cleartypeNoBg: true,
			timeoutFn: calculateTimeout 
		}); 
	});     
 
	function calculateTimeout(currElement, nextElement, opts, isForward) { 
		// here we set even number slides to have a 2 second timeout; 
		// by returning false for odd number slides we let those slides 
		// inherit the default timeout value (4 sec) 
		var index = opts.currSlide;
		return (index % 2) ? 250 : 6000; 
	} 
}

function homeBannerCycle2(){
	$(function() { 
		$('#bannerAnimation2').cycle({ 
			fx:     'fade', 
			speed:  2000, 
			delay:250,
			cleartypeNoBg: true,
			timeoutFn: calculateTimeout 
		}); 
	});     
 
	function calculateTimeout(currElement, nextElement, opts, isForward) { 
		// here we set even number slides to have a 2 second timeout; 
		// by returning false for odd number slides we let those slides 
		// inherit the default timeout value (4 sec) 
		var index = opts.currSlide;
		return (index % 2) ? 250 : 6000; 
	} 
}

function skinTableContent(){
	$(".generalContent table tr").each(function(){
		$(this).find("td:last").addClass("last");
	})
}

function rightMenu(){
	if($(".generalContent #rightMenu").children().size() > 0){
		$(".generalContentInner").css("width","614px");
	} else{
		$("#rightMenu").hide();
		$(".generalContentInner").css("width","939px");
	}
}

function ajustementFooter(){
	$("#footer li li:even").addClass("even");
	$("#footer li li:odd").addClass("odd");
	$("#footer li li.even").each(function(){
		indexGroupLi= $("#footer li li:even").index($(this));
		if( $(this).height() > $("#footer li li:odd").eq(indexGroupLi).height()){
			 $("#footer li li:odd").eq(indexGroupLi).css("height", $(this).height()+"px");
		}
	})
	maxHeightFooter = 0;
	QtyFooterTitle = $("#footer ul .titleFooter").size();
	$("#footer").each(function(){
		for(i=0; i<QtyFooterTitle; i++){
			if( $(this).find(".titleFooter").eq(i).height()>maxHeightFooter ){
				
				maxHeightFooter = $(this).find(".titleFooter").eq(i).height();
			}
		}	
	
		for(i=0; i<QtyFooterTitle; i++){
			$(this).find(".titleFooter").eq(i).css("height",maxHeightFooter+"px");
		}
	})
		
}
function applyWatermark() {
		$('.watermark').each(function(){
			   if ($(this).val() == $(this).attr('title')) {$(this).addClass('on');}
			   $(this).focus(function(){
					   $(this).filter(function() {return $(this).val() == "" || $(this).val() == $(this).attr('title')}).removeClass("on").val("");
					   $(this).removeClass("swap_value");
			   });
			   $(this).blur(function(){
					   $(this).filter(function() {return $(this).val() == ""}).addClass("on").val($(this).attr('title'));
					   $(this).addClass("swap_value");
			   });
		});
}

function adjustRowHeight(){
    var maxHeightTopics = 0;
	$(".adjustRowHeight tr").each(function(){
		var coll = $('.contentBlock', $(this));
		for(var i=0; i< coll.size(); i++){
			if( coll.eq(i).height() > maxHeightTopics){
				maxHeightTopics = coll.eq(i).height();
			}
		}
		for(i=0; i<coll.size(); i++){
			coll.eq(i).css("height",maxHeightTopics+10+"px");
		}
		maxHeightTopics = 0;
	});
}
function addIEClass(){
	if ($.browser.msie) {
		$("body").addClass("IE");
	 } 
}


