var count = 0  //for slider1

$.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		$("<img>").attr("src", arguments[i]);
	}
}
$(function(){
	$.preloadImages("images/menu_over.gif", "images/menu_over.png");
	if ($.browser.msie && $.browser.version <= 6.0)
	{
		correctPNG();
	}

	$("#mn-level1 > li > a").click(function(){
		var indx = $("#mn-level1 > li > a").index(this);
		
		$(".mn-level2").slideUp("slow");
		$(".mn-level2 > li > a").removeClass("active");
		$(".mn-level3").slideUp("slow");
		$(".mn-level3 > li > a").removeClass("active")

		var status1 = $("#mn-level1 > li").eq(indx).find(".mn-level2").css("display");
		if (status1 == 'none')
		{
			$("#mn-level1 > li").eq(indx).find(".mn-level2").slideDown("slow");
			$("#mn-level1 > li > a").removeClass("active").eq(indx).addClass("active");
		}
		else if (status1 == 'block')
		{
			$("#mn-level1 > li > a").removeClass("active");
		}
		else
		{
			$("#mn-level1 > li > a").removeClass("active").eq(indx).addClass("active");
		}
		var sec = $(this).attr("rel");
		$(".cont-wrap").hide();
		if (sec=='')
			$("#default_txt").show();
		else
			$("#"+sec).show();
	});

	$(".mn-level2 > li > a").click(function(){
		$(".mn-level3").slideUp("slow");
		$(".mn-level3 > li > a ").removeClass("active");

		var indx = $(".mn-level2 > li > a").index(this);
		var status2 = $(".mn-level2 > li").eq(indx).find(".mn-level3").css("display");
		if (status2 =='none')
		{
			$(".mn-level2 > li").eq(indx).find(".mn-level3").slideDown("slow");
			$(".mn-level2 > li > a").removeClass("active").eq(indx).addClass("active");
		}
		else if (status2 == 'block')
		{
			$(".mn-level2 > li > a").removeClass("active");
		}
		else
		{
			$(".mn-level2 > li > a").removeClass("active").eq(indx).addClass("active");
		}
		var sec = $(this).attr("rel");
		$(".cont-wrap").hide();
		if (sec=='')
			$("#default_txt").show();
		else
			$("#"+sec).show();
	});
	
	$(".mn-level3 > li > a").click(function(){
		var indx = $(".mn-level3 > li > a").index(this);
		$(".mn-level3 > li > a").removeClass("active").eq(indx).addClass("active");
		var sec = $(this).attr("rel");
		$(".cont-wrap").hide();
		if (sec=='')
			$("#default_txt").show();
		else
			$("#"+sec).show();
	}); 

	/*
	$(".mn-rgt-2 > li > a").toggle(
		function () {
			$(".mn-rgt-3").slideDown("slow");
		},
		function () {
			$(".mn-rgt-3").slideUp("slow");
	});
	*/
	$(".mn-rgt-2 > li > a").click(function(){
		var indx = $(".mn-rgt-2 > li > a").index(this);
		var status1 = $(".mn-rgt-3").eq(indx).css("display");
		if (status1=='none')
		{
			//$(".mn-rgt-3").slideUp("slow").eq(indx).slideDown("slow");
			$(".mn-rgt-3").eq(indx).slideDown("slow");
		}
		else
		{
			//$(".mn-rgt-3").slideUp("slow")
			$(".mn-rgt-3").eq(indx).slideUp("slow");
		}
	});

	$(".mn-style > li > a").click(function(){
		var indx = $(".mn-style > li > a").index(this);
		$(".img-box").hide();
		$("#"+$(this).text()).show();
		$(".mn-style > li > a").removeClass("active").eq(indx).addClass("active");
	});
	$('.ul_style1 li > a').click(function (){
		var indx = $('.ul_style1 li > a').index(this);
		if ($('.ul_style1 li > a ~ div').eq(indx).css('display')=='none')
		{
			$('.ul_style1 li > a').removeClass("active");
			$('.ul_style1 li > a').eq(indx).addClass("active");
			$('.ul_style1 li > a ~ div').slideUp('slow');
			$('.ul_style1 li > a ~ div').eq(indx).slideDown('slow');
		}
		else
		{
			$('.ul_style1 li > a').eq(indx).removeClass("active");
			$('.ul_style1 li > a ~ div').eq(indx).slideUp('slow');
		}
	});

	// for slider1
	var alertTimerId = 0;

	var w_mid = $(".mid").width();
	var w_lst = $("#lst > table").width();
	var w_li = $("#lst > table tr td:first").width();
	w_li = w_li * 3;
	$(".last > a").click(function (){
		MoveFront(( w_lst - w_li ),w_li);
	});
	$(".first > a").mousedown(function (){
		MoveBack( w_li);
	});

	//Map
	/*
	$("#map").click(function (){
		$(".slider").hide();
	}); */
});
function showSection(id1,id2)
{
	$("."+id2).hide();
	$("#"+id1).show();	
}

function show_ctg(id)
{
	$(".img-box").hide();
	$("#"+id).show();
}
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) 
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }    
}
function MoveFront(t,w)
{
	count = count + w;
	if (count <= t)
	{
		$("#lst > table").animate( { marginLeft:"-"+count+"px"}, 1500 );
		$('.first > a').css({'backgroundImage': 'url(../images/arrows_h.gif)','backgroundRepeat': 'no-repeat','backgroundPosition': '0px 50%'});
	}
	else
	{
		count = t;
		$("#lst >table").animate( { marginLeft:"-"+count+"px"}, 1500 );
		$('.last > a').css({'backgroundImage': 'url(../images/arrows_h.gif)','backgroundRepeat': 'no-repeat','backgroundPosition': '-46px 50%'});
	}
}
function MoveBack(w)
{
	count = count - w;
	if (count >= 1)
	{
		$("#lst >table").animate( { marginLeft:"-"+count+"px"}, 1500 );
		$('.last > a').css({'backgroundImage': 'url(../images/arrows_h.gif)','backgroundRepeat': 'no-repeat','backgroundPosition': '-16px 50%'});
	}
	else
	{
		count = 0;
		$("#lst > table").animate( { marginLeft:"-"+count+"px"}, 1500 );
		$('.last > a').css({'backgroundImage': 'url(../images/arrows_h.gif)','backgroundRepeat': 'no-repeat','backgroundPosition': '-16px 50%'});
		$('.first > a').css({'backgroundImage': 'url(../images/arrows_h.gif)','backgroundRepeat': 'no-repeat','backgroundPosition': '-30px 50%'});
	}
}

