$(document).ready(function() {


	//menu part
/*
		$(".gnav_li").mouseenter(function(){
			//alert($(this).children("a").html());
			if($(this).children("a").hasClass("menu_active")==false){
				//$(this).children("a").css( "backgroundImage","url(images/bg_nav_.png)");
				$(this).children("a").stop().fadeTo(500,0.1);
				$("ul.gnav_sub_ul",this).css("display","block");
				//$("div.menu_sub_div",this).stop().fadeIn(300,function(){$(this).css("opacity","").css("display","block");});
			}
		});
		$(".gnav_li").mouseleave(function(){
			if($(this).children("a").hasClass("menu_active")==false){
				//$(this).children("a").css( "backgroundImage","url(images/bg_nav.png)");
				$(this).children("a").stop().fadeTo(200,1);
				$("ul.gnav_sub_ul",this).stop().fadeOut(200,function(){$(this).css("opacity","");});
			}
		});
*/
    if ($("#ajaxImage").html() != "") {
//        $("#ajaxImage").scrollable({ size: 1, loop: true, clickable: false, next: ".btnNext", prev: ".btnPrevious" }).circular().autoscroll({ interval: 5000 });
    }

/*m_brand1 /images/m_brand_1.jpg*/
	$("li.m_brand1").mouseenter(function(){
			if($("li.m_brand1 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:188px;height:147px;background:url(/images/m_brand_1.jpg) center bottom no-repeat;'><a href='/hansa' style='background:none;' title='Find out more about hansa products:mixer tap,showers,bath spout,sink mixers,valves'>&nbsp;</a></div>");
			}
			$("li.m_brand1 div").stop().fadeIn(300);
	});
	$("li.m_brand1").mouseleave(function(){
			$("li.m_brand1 div").stop().fadeOut(100);
	});
	$("li.m_brand2").mouseenter(function(){
			if($("li.m_brand2 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:128px;height:147px;background:url(/images/m_brand_2.jpg) center bottom no-repeat;'><a href='/kwc' style='background:none;' title='Find out more about kwc products: mixer tap,sink mixers,bath spout'>&nbsp;</a></div>");
			}
			$("li.m_brand2 div").stop().fadeIn(300);
	});
	$("li.m_brand2").mouseleave(function(){
			$("li.m_brand2 div").stop().fadeOut(100);
	});
	$("li.m_brand3").mouseenter(function(){
			if($("li.m_brand3 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:131px;height:147px;background:url(/images/m_brand_3.jpg) center bottom no-repeat;'><a href='/emco' style='background:none;' title='Find out more about emco products:towel rail,towel rings'>&nbsp;</a></div>");
			}
			$("li.m_brand3 div").stop().fadeIn(300);
	});
	$("li.m_brand3").mouseleave(function(){
			$("li.m_brand3 div").stop().fadeOut(100);
	});
	$("li.m_brand4").mouseenter(function(){
			if($("li.m_brand4 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:158px;height:147px;background:url(/images/m_brand_4.jpg) center bottom no-repeat;'><a href='/schell' style='background:none;' title='Find out more about schell products:mixer tap'>&nbsp;</a></div>");
			}
			$("li.m_brand4 div").stop().fadeIn(300);
	});
	$("li.m_brand4").mouseleave(function(){
			$("li.m_brand4 div").stop().fadeOut(100);
	});
	$("li.m_brand5").mouseenter(function(){
			if($("li.m_brand5 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:146px;height:147px;background:url(/images/m_brand_5.jpg) center bottom no-repeat;'><a href='/virtu' style='background:none;' title='Find out more about virtu products: towel rail,towel rings,bath spout'>&nbsp;</a></div>");
			}
			$("li.m_brand5 div").stop().fadeIn(300);
	});
	$("li.m_brand5").mouseleave(function(){
			$("li.m_brand5 div").stop().fadeOut(100);
	});
	$("li.m_brand6").mouseenter(function(){
			if($("li.m_brand6 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:171px;height:147px;background:url(/images/m_brand_6.jpg) center bottom no-repeat;'><a href='/sanitron' style='background:none;' title='Find out more about sanitron products: sensor taps, flush valve'>&nbsp;</a></div>");
			}
			$("li.m_brand6 div").stop().fadeIn(300);
	});
	$("li.m_brand6").mouseleave(function(){
			$("li.m_brand6 div").stop().fadeOut(100);
	});



	$("#gnav ul.lev1 li.lev1").mouseenter(function(){
		if( $("ul",this).html() !=null ){
			$("ul",this).css("display","block");
		}
	});

	$("#gnav ul.lev1 li.lev1").mouseleave(function(){
		if( $("ul",this).html() !=null ){
			$("ul",this).css("display","none");
		}
	});

/*
	$("#gnav li.gnav1").mouseenter(function(){
			if($("#gnav li.gnav1 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:203px;height:43px;background:url(/images/gnav_1.jpg) center bottom no-repeat;'><a href='/home' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav1 div").stop().fadeIn(300,function(){$(this).css("opacity","");})
	});
	$("#gnav li.gnav1").mouseleave(function(){
			$("#gnav li.gnav1 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav2").mouseenter(function(){
			if($("#gnav li.gnav2 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:146px;height:43px;background:url(/images/gnav_2.jpg) center bottom no-repeat;'><a href='/about-us' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav2 div").stop().fadeIn(300,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav2").mouseleave(function(){
			$("#gnav li.gnav2 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav3").mouseenter(function(){
			if($("#gnav li.gnav3 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:152px;height:43px;background:url(/images/gnav_3.jpg) center bottom no-repeat;'><a href='/consumers/brands' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav3 div").stop().fadeIn(300,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav3").mouseleave(function(){
			$("#gnav li.gnav3 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav4").mouseenter(function(){
			if($("#gnav li.gnav4 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:128px;height:43px;background:url(/images/gnav_4.jpg) center bottom no-repeat;'><a href='/news' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav4 div").stop().fadeIn(300,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav4").mouseleave(function(){
			$("#gnav li.gnav4 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav5").mouseenter(function(){
			if($("#gnav li.gnav5 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:153px;height:43px;background:url(/images/gnav_5.jpg) center bottom no-repeat;'><a href='/specifiers' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav5 div").stop().fadeIn(300,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav5").mouseleave(function(){
			$("#gnav li.gnav5 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav6").mouseenter(function(){
			if($("#gnav li.gnav6 div").html()==null){
				$(this).prepend("<div style='position:absolute;display:none;width:178px;height:43px;background:url(/images/gnav_6.jpg) center bottom no-repeat;'><a href='/contactus' style='background:none;'>&nbsp;</a></div>");
			}
			$("#gnav li.gnav6 div").stop().fadeIn(300,function(){$(this).css("opacity","");});
	});
	$("#gnav li.gnav6").mouseleave(function(){
			$("#gnav li.gnav6 div").stop().fadeOut(100,function(){$(this).css("opacity","");});
	});

*/


	/*$("#taps_nav li a").click(function(){
		$("#taps_nav li a").attr("class","");
		//$(this).parent().attr("class").;
		//alert(tmp.html());
		if($(this).attr("class")=="active"){
			$(this).attr("class","");
		}else{
			$(this).attr("class","active");
		}
	});*/




    $("#sp_1_val").focus(function() {
        if ($(this).val() == "Name / Product No.") {
            $(this).val("");
        }
    });

    $("#sp_1_val").blur(function() {
        if ($(this).val() == "") {
            $(this).val("Name / Product No.");
        }
    });

    // clean form

	$("input[name$='txtSearch']").val("");
    if ($("input[name$='txtBrand']").val() != 0) {
        $("input[name$='txtBrand']").val(0);
    }
    if ($("input[name$='txtCategory']").val() != 0) {
        $("input[name$='txtCategory']").val(0);
    }
    if ($("input[name$='txtRange']").val() != 0) {
        $("input[name$='txtRange']").val(0);
    }

    $("#sp_1_val").change(function() {
    $("input[name$='txtSearch']").val($("#sp_1_val").val());
        
    });

    $("div.sp_2 div.sp_btn").click(function() {
		//alert("Hello0");
        $("div.sp_sub2 ul").html($("div.sp_brand").html());
        $("div.sp_sub2").toggle();
        $("div.sp_sub3").hide();
        $("div.sp_sub4").hide();
        $("div.sp_sub2 ul li").click(function() {

            brand = $(this).html();
            idx = $(this).attr("idx");
            cid = $(this).attr("cid");
            $("#search_product_brand").val(brand);

            $("input[name$='txtBrand']").val(cid); //find and change.
                

            $("#sp_2_val").val(cid);
            $("div.sp_sub2").hide();
            //alert(cid);
            //alert($("div[cid='"+cid+"']").innerHTML);
            /*			
            tmp_html="";
            for(i=0;i<$("div.sp_range").size();i++){
            if(cid==$("div.sp_range")[i].attr("cid")){
            tmp_html=$("div.sp_range")[i].innerHTML;
            }
            }
            */
            $("div.sp_sub3 ul").html($("div." + cid)[0].innerHTML);
            //$("div.sp_sub4 ul").html($("div.sp_type")[idx].innerHTML);

            $("#search_product_category").val("Category");
            $("#sp_3_val").val("");
			 $("input[name$='txtCategory']").val(0);
            $("#search_product_range").val("Range");
            $("#sp_4_val").val("");
			 $("input[name$='txtRange']").val(0);
			click_subs();
///////////////////////////////
		//	category = $(this).html();
			//idx = $(this).attr("idx");
		//	cid = $(this).attr("cid");
		//	 $("#search_product_category").val(category);
			//$("#plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneMain_ProductSearchBox_txtCategory").val(cid);
			// $("#sp_3_val").val(cid);
	
			$("#search_product_range").val("Range");
			$("#sp_4_val").val("");
			$("div.sp_sub4 ul").html($("div.allcat." + cid)[0].innerHTML);

			$("div.sp_sub3").hide();
			li_over();
			$("div.sp_sub4 ul li").click(function() {
				subtype = $(this).html();
				idx = $(this).attr("idx");
				cid = $(this).attr("cid");
				 $("#search_product_range").val(subtype);
				 $("input[name$='txtRange']").val(cid);
				$("#sp_4_val").val(cid);
				 $("div.sp_sub4").hide();
			});








//////////////////////////////

            //click_subs();
        });
        li_over();
    });
    $("div.sp_3 div.sp_btn").click(function() {
        $("div.sp_sub3").toggle();
        $("div.sp_sub2").hide();
        $("div.sp_sub4").hide();
        li_over();
    });
    $("div.sp_4 div.sp_btn").click(function() {
        $("div.sp_sub4").toggle();
        $("div.sp_sub2").hide();
        $("div.sp_sub3").hide();
        li_over();
    });








    $("div.sp_btn").mouseover(function() {
        $(this).css("background-color", "#f0f0f0");
    });
    $("div.sp_btn").mouseout(function() {
        $(this).css("background-color", "#ffffff");
    });


});



function li_over(){
	$("div.sp_div ul li").mouseover(function(){
		$(this).css("background-color","#f0f0f0");
	});
	$("div.sp_div ul li").mouseout(function(){
		$(this).css("background-color","#ffffff");
	});

}

function click_subs() {
    $("div.sp_sub3 ul li").click(function() {
        category = $(this).html();
        idx = $(this).attr("idx");
        cid = $(this).attr("cid");
		catid = $("input[name$='txtBrand']").val();
        $("#search_product_category").val(category);
        $("input[name$='txtCategory']").val(cid);
        $("#sp_3_val").val(cid);

        $("#search_product_range").val("Range");
        $("#sp_4_val").val("");
		$("input[name$='txtRange']").val(0);
        $("div.sp_sub4 ul").html($("div.subcat." + cid)[0].innerHTML);

        $("div.sp_sub3").hide();
        li_over();
        $("div.sp_sub4 ul li").click(function() {
            subtype = $(this).html();
            idx = $(this).attr("idx");
            cid = $(this).attr("cid");
            $("#search_product_range").val(subtype);
	        $("input[name$='txtRange']").val(cid);
            $("#sp_4_val").val(cid);
            $("div.sp_sub4").hide();
        });
    });
    /*
    category = $(this).html();
    idx = $(this).attr("idx");
    cid = $(this).attr("cid");
    */
}