// JQUERY FUNCTION




$(function() {

	$(".main h1:eq(0)").css({ marginTop:"0" });
	$(".main h2:eq(0)").css({ marginTop:"0" });
	$("#home .main h3:eq(0)").css({  marginTop:"0" });
	$("#submenu a:eq(0)").css({ border:"0","padding-left":"0" });
	$(".main h1 + h2").css({  marginTop:"0" });
	$(".main h1 + h2").css({  marginTop:"0" });
	$(".main h1 + h2").prev().css({ marginBottom:"0" });
	$(".main p + ul").prev().css({ marginBottom:"0.5em" });
	$(".main li").wrapInner("<span></span>");
	
	$(".package").css({ marginBottom:"0.5em" });
	
	// Remove margin right every 3 products
	function removeMarginFromList(target,numberByRow){
		
		var numberLi = $(target).length;
		var j=0;
		var k=0;
		for(i=0;i<numberLi;i++)
		{
			j++;
			if(j==numberByRow)
			{
				k++;
				var li = (j*k)-1;
				$(target+":eq("+li+")").css({ "margin-right":"0" });
				j=0;
				//alert(li);
			}
		}
	}


	// Remove Margin Right every 3 products
	removeMarginFromList(".package",2);

	
	
	// HOME PAGE LAYOUT
	$("#home .main p:eq(1) ~ *").hide();
	$("#home .main img:gt(0)").hide();
	
	$("#home .itin p:eq(1) ~ *").hide();
	$("#home .itin img:gt(0)").hide();
	//$("#home p:eq(1)").append("<p class='wantMore'><a href='#'>Want to know more ? Click here</a></p>");
	//$('#home .wantMore a').click(function(){
		//$("#home .main *").show();
	//});
	
	$("#home .showHide").toggle(
		function () {
			$(this).css({"background-position":"-20px 0"});
			$("#home .main *").show();
		},
		function () {
			$(this).css({"background-position":"0 0"});
			$("#home .main p:eq(1) ~ *").hide();
			$("#home .main img:gt(0)").hide();
		}
	);
	
	$("#home .showHide").toggle(
		function () {
			$(this).css({"background-position":"-20px 0"});
			$("#home .itin *").show();
		},
		function () {
			$(this).css({"background-position":"0 0"});
			$("#home .itin p:eq(1) ~ *").hide();
			$("#home .itin img:gt(0)").hide();
		}
	);
	
	
	$("#news .news h4 a").attr("href","#");
	$("#news .news h4 a").click(
		function () {
			$("#news .news .content").css({"display":"none"});
			$("#news .news .excerpt").css({"display":"block"});
			$(this).parent().next(".excerpt").css({"display":"none"});
			$(this).parent().parent().children(".content").css({"display":"block"});
		}
	);
	
	
	// IMAGE WITH CLASS PICTURE WILL WORK WITH THICKBOX
	$("#colleft img.picture, #colleft img[longdesc]").each(function(){		
  	//var stop = $(this).attr("src").indexOf("-256_x.jpg");
		//var sublink = $(this).attr("src").substring(0,stop);
		
		var rel = $(this).attr("rel");
		var longdesc = $(this).attr("longdesc");
		
		if(longdesc =='' || longdesc ==undefined)
		{
			var link = rel;
		}
		else
		{
			var link = longdesc;
		}
		
		$(this).wrap("<a href=\""+link+"\" class=\"thickbox\"></a>");
		$(this).removeAttr("title");
	});
	

	// Highlighted the link on the menu when is the right page
	var hreflength = location.href.length;
	var href = location.href.substring(location.href.lastIndexOf( "/" )+1,hreflength);
	

	$("#automenu li").each(function(){
		var li = $(this);
		
		if($("a[@href^='"+ href +"']", li).is("a") && href!="")
		{
			li.addClass("selected");
		}
	});
	
	
	$("#colright li").each(function(){
		if($(this).children("a").attr("href") == href  && href!="")
		{
			$(this).addClass("selected");
			$(this).parent().css({"display":"block"});
			$(this).parent().prev().css({"background-color":"#D3B185","font-weight":"bold"});
		}
	});
	
	
	
	if(href=="")
		{
			$("#automenu li:eq(0)").addClass("selected");
		}
	
	
	// MENU RIGHT HIDE SHOW
	
	$("#colright h4").toggle(
		function () {
			$("#colright h4").css({"background":"none","font-weight":"normal","color":"#9F7A4F"});
			$("#colright ul").css({"display":"none"});
			$(this).next().css({"display":"block"});
			$(this).css({"background-color":"#D3B185","font-weight":"bold","color":"#fff"});
		},
		function () {
			$("#colright h4").css({"background":"none","font-weight":"normal","color":"#9F7A4F"});
			$("#colright ul").css({"display":"none"});
		}
	);
	
	
	// PAGE NAVIGATION SHOW HIDE

	var page = $("#pages li").size();
	if(page < 6)
	{
		$("#pages").remove();
	};
	
	var contentArea = $("#contentArea *").get();
	if(contentArea.length <=1)
	{
		$("#contentArea h1").after("No results for this page");
	}
	
	// TARGET BLANK XHTML STRICT
	$('a[@rel$="external"]').click(function(){
	
		this.target = "_blank";
	
	});

	
	

	/*
	
	$(":text").css({border:"1px solid #cc6699",background:"#F5EBF0"})
	$(".form :text").css({width:"380px"})
	
	
	$(".main tr")
	.mouseover(
		function(){
			$(this).css({ background:"#EFEFEF"});
			$(this).children("th").css({ paddingLeft:"5px"});
		})
	.mouseout(
		function(){
			$(this).css({ background:"none"});
			$(this).children("th").css({ paddingLeft:"0"});
		});
	*/
	
	



	
});