$(document).ready(function(){
	$('#wrap').pngFix();
	$("#head h1.logo").click(function(){
		document.location.href='/';
	});

	if($("#promotion").html()!=""){
		$("#promotion_tab").hide();
		$("#promotion").css("margin-top",340);
	}
if($("#promotion").html()!=""){
		$("#item_pro").scrollable({size:4,loop:true,clickable:false,next:".pre_pro",prev:".next_pro"}).circular().autoscroll({interval:4000});
		$("a.close_promo").click(function(){
			$("#promotion").hide();
			$("#promotion_tab").show();
		});
		$("#promotion_tab").click(function(){
			$("#promotion").show();
			$("#promotion_tab").hide();
		});
	}
	if($("#cc_slide").html()!=""){
		$("#cc_slide").scrollable({size:3,loop:true,clickable:false,next:"#ccc_next",prev:"#ccc_pre"}).circular().autoscroll({interval:2500});
	}

	$("#storename").keydown(function(event){
		if(event.keyCode==13){
			return false;
		}
	});
	$("#addressInput").keydown(function(event){
		if(event.keyCode==13){
			return false;
		}
	});

	if($("#ajaxImage").html()!=""){
		$("#ajaxImage").scrollable({size:1,loop:true,clickable:false,next:".btnNext",prev:".btnPrevious"}).circular().autoscroll({interval:5000});
	}

	$("#gnav li.gnav2").mouseover(function(){
		$("#products_menu").show();
		$("#gnav li.gnav2 a.gnav2").css("background-position","0 -29px");
	});
	$("#gnav li.gnav2").mouseout(function(){
		$("#products_menu").hide();
		$("#gnav li.gnav2 a.gnav2").css("background-position","0 0");
	});


	$("#gnav li.gnav1").mouseover(function(){
		$("#aboutus_menu").show();
		$("#gnav li.gnav1 a.gnav1").css("background-position","0 -29px");
	});
	$("#gnav li.gnav1").mouseout(function(){
		$("#aboutus_menu").hide();
		$("#gnav li.gnav1 a.gnav1").css("background-position","0 0");
	});





	$("#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.");
		}
	});

	$("#sp_1_val").change(function(){
		$("#ctl00_productSearchEngine_txtProductName").val($("#sp_1_val").val());
	});

	






	$("div.sp_2 div.sp_btn").click(function(){

		$("div.sp_sub2 ul").html($("div.sp_category").html());
		$("div.sp_sub2").toggle();
		$("div.sp_sub3").hide();
		$("div.sp_sub4").hide();
		$("div.sp_sub2 ul li").click(function(){
			category = $(this).html();
			idx = $(this).attr("idx");
			cid = $(this).attr("cid");
			$("#search_product_category").val(category);

			$("#ctl00_productSearchEngine_ddlCategory2").val(cid);

			$("#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_range").val("Range");
			$("#sp_3_val").val("");
			$("#search_product_subtype").val("Sub Type");
			$("#sp_4_val").val("");

			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(){
		range = $(this).html();
		idx = $(this).attr("idx");
		cid = $(this).attr("cid");
		$("#search_product_range").val(range);
		$("#ctl00_productSearchEngine_ddlRange2").val(cid);
		$("#sp_3_val").val(cid);

		$("#search_product_subtype").val("Sub Type");
		$("#sp_4_val").val("");
		$("div.sp_sub4 ul").html($("div."+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_subtype").val(subtype);
			$("#ctl00_productSearchEngine_ddlProductSubType2").val(cid);
			$("#sp_4_val").val(cid);
			$("div.sp_sub4").hide();
		});
	});
/*
			category = $(this).html();
			idx = $(this).attr("idx");
			cid = $(this).attr("cid");
*/

}





var headerHeight = 93;
var footerHeight = 119; 
var pageTimer = null;
var resizeTimer = null;
	    
$(document).ready(function(){  
    //Check screen size on resize
	//setInterval(resizeFlash,"500");
    $(window).resize(function(){
        //timer to wait for resize to be complete
        resizeFlash();
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(resizeFlash, 100);
    });
               
    resizeFlash();
    pageTimer = setTimeout(resizeFlash, 200);
    

});

function resizeFlash(){
    if($('#flashMovie').height()>40){
        //Safety check for slow load ie6
        if (pageTimer) clearTimeout(pageTimer);    
        
        //Set dark bg
        if($('.homeContent').length<1){ 
//            $(document.body).css('background', '#272624');
            
            //$('#maxHeight').css('height','auto');
            //$('#aspnetForm').css('height','auto');
        }
        
        //Check screen size
        var screenHeight = $(window).height();
        var screenWidth= $(window).width();
        
        if(screenHeight < 620) screenHeight = 620;    
	    //if(screenWidth < 974) screenWidth = 974;


	    var is_ie6 = ('ActiveXObject' in window && !('XMLHttpRequest' in window));
	    if (is_ie6) {
	        //screenHeight += footerHeight;
	    };
	    
	    screenHeight -= (headerHeight + footerHeight);

//	$("div.picture").html(screenHeight+$("div.picture").html());


	    $('#homeFlashContainer').css('height', screenHeight+'px');
//	    $('#homeFlashContainer').css('height', 779+'px');

	    //$('#homeFlashContainer').css('width', screenWidth-36+'px');
    	
    	
        $('#maxHeight').css('height','100%');
        $('#aspnetForm').css('height','100%');
        
        var footerY = screenHeight + headerHeight;

		reposition_promodiv(screenHeight);
    }
}

function reposition_promodiv(screenHeight){
    $('#promotion').css('margin-top',screenHeight-220);
    $('#promotion_tab').css('margin-top',screenHeight-43);
}
