$(document).ready(function() {

//if is product template,change the navigation
/*
if((nav!=''||parentType!='')&& supportKeyword=='false')
{	navigation();	}
*/



$(window).resize(function() {
    var width = $(this).width();
	var shellwidth=$("#shell").width()+58;
	if(width<shellwidth)
		$("#PopupBackground").width(shellwidth);
	else
		$("#PopupBackground").css("width","100%");
});

//supportvalue¡¢supplyvalueÈ«¾Ö?Á¿
//var supportvalue="Enter product name or code";
//var supplyvalue="Search for your genuine Epson ink."
	searchValueClear("f_product_supply",supplyvalue);
	searchValueClear("f_product",supportvalue);//clear search input default value
	jQuery( '.f_tooltip' ).each( function(){ 
			
			try{		
						if ( jQuery( this ).prev( '.f_tooltip_text' ).length )
				{
					jQuery( jQuery( this ).prev( '.f_tooltip_text' )[0] ).bind( 'mouseover', function()
					{
						var icon = jQuery( jQuery( this ).next( '.f_tooltip' )[0] );
						tipOpen( jQuery( this ).offset().top, jQuery( this ).offset().left-30, icon.html() );
					} ).bind( 'mouseout',closed );

					jQuery( this ).css( { padding:0 } );
				}
				else
				{
					jQuery( this ).bind( 'mouseover', function(){
						tipOpen( jQuery( this ).offset().top, jQuery( this ).offset().left-30, jQuery( this ).html() );
					} ).bind( 'mouseout', closed );
				}
				}catch(e){alert(e);}
			} );

	promotion();
	
	

    $('.body').bind('click',
    function(e) {
    var clickme = $(e.target);
    if (!clickme.parents().hasClass("selCountryContainer") && !clickme.parents().hasClass("jsDropdownCountryMenu") && !clickme.parents().hasClass("jsDropdown") && !clickme.parents().hasClass("country_show")) {
            $("#dropdown_country").hide();
            $("#jsDropdownCountryMenu").hide();
            $("#jsDropdownLangMenu").hide();
       } 
	   
    });

    $("#otherBanner .blockTeaser h5").mouseover(function() {
        $(this).addClass("hover");
    });
    $("#otherBanner .blockTeaser h5").mouseout(function() {
        $(this).removeClass("hover");
    });

    $("input").focus(function() {
        $(this).addClass("focus");
    });
    $("input").blur(function() {
        $(this).removeClass("focus");
    });

	$("#fliter  h4 span").mouseover(function() {
        $(this).addClass("hover");
    });
    $("#fliter  h4 span").mouseout(function() {
        $(this).removeClass("hover");
    });
	
 /*   $("#fliter .activex").each(function() {
        var iewidth = $(this).width();        
        iewidth = iewidth + 6;
        var ffwidth = iewidth - 6;
        $(this).parent().attr("style", "width:" + ffwidth + "px !important;" + "width:" + iewidth + "px");
        var iefieldset = iewidth + 35;
        var fffieldset = iewidth;
        $(this).parent().parent().parent().attr("style", "width:" + fffieldset + "px !important;" + "width:" + iefieldset + "px");
    });*/
	
	
	$("#fliter ul").each(function() {
        var iewidth = $(this).width();
		if($(this).hasClass("activex"))
		{//alert("P");
		iewidth = iewidth + 6;
        var ffwidth = iewidth - 6;
        $(this).parent().attr("style", "width:" + ffwidth + "px !important;" + "width:" + iewidth + "px");
        var iefieldset = iewidth + 29;
        var fffieldset = iewidth;
        $(this).parent().parent().parent().attr("style", "width:" + fffieldset + "px !important;" + "width:" + iefieldset + "px");
		}
		else
		{//alert(iewidth);		
		var iefieldset = iewidth + 29;
        var fffieldset = iewidth;
        $(this).parent().attr("style", "width:" + fffieldset + "px !important;" + "width:" + iefieldset + "px");
		}
    });

    $("#fliter").find("li").click(function() {
    
        if (product_count_response == null || product_count_response == 0) {
    
            if (!$(this).hasClass("disabled")){			
                var criteriaid = "";
                if ($(this).hasClass("checkbox")) {
                    $(this).toggleClass("active");
                    $(this).parent().addClass("activex");
                }
                else {
                    $(this).parent().find("li").removeClass("active");
                    $(this).addClass("active");
                    $(this).parent().addClass("activex");
                }


                criteriaid = getType();			
                productshow(typeid, criteriaid, lang, imgpath, 1, 'true')

            }
        
        }
    });



});

    function menuShow(obj){
    $(obj).find("div.genericRoundedCorners:first").show();}

    function menuHide(obj){
    $(obj).find("div.genericRoundedCorners:first").hide();}

/*
    function leftmenu1(obj){	
    if($(obj).find("h4").hasClass("selected"))
    {
    $(obj).find("h4").removeClass("selected");
	
   
	$(obj).find("ul").slideUp("slow");
    }
    else
    {
    $(".heroNavigation").find("h4.selected").each(function(){

    $(this).removeClass("selected");
    $(this).parent().find("ul").slideUp("slow");

    });
    $(obj).find("h4").addClass("selected");
    $(obj).find("ul").slideDown("slow");

    }

    }
*/	
	function leftmenu(obj){	
    if($(obj).hasClass("selected"))
    {
    $(obj).removeClass("selected");
	
    //$(obj).find("ul").addClass("leftHeight");
	$(obj).parent().find("ul").slideUp("slow");
    }
    else
    {
    $(".heroNavigation").find("h4.selected").each(function(){

    $(this).removeClass("selected");
    $(this).parent().find("ul").slideUp("slow");

    });
    $(obj).addClass("selected");
    $(obj).parent().find("ul").slideDown("slow");

    }

    }

    function getType(){
    var filterid="",criteriaid="";
    $("#fliter").find("ul").each(function(){
    if($(this).hasClass("activex"))
    {
    var length='false'
    var b;
    var a=$(this).attr("class");
    b=a.split(" ");
    $(this).find("li").not(".disabled").each(function(){
    if($(this).hasClass("active"))
    {
    var bc;
    //length='true';
    var ac=$(this).attr("class");
    bc=ac.split(" ");
    criteriaid+=b[1]+","+bc[1]+"|";
    }
    });
    if(length=='true')
    {
    criteriaid=criteriaid.substr(0,criteriaid.length-1);
    criteriaid+="_";
    }
    }
    });
    criteriaid=criteriaid.substr(0,criteriaid.length-1);
    return criteriaid;
    }

    function getAll(){
    var criteriaid='';
    $("#fliter").find("ul").each(function(){
    $(this).removeClass("activex");
    $(this).find("li").each(function(){
    $(this).removeClass("disabled");
    $(this).removeClass("active");
    });
    /*if($(this).find("li:first").hasClass("radio"))
    {
    $(this).addClass('activex');
    $(this).find("li:first").addClass('active');
    var b;
    var a=$(this).attr("class");
    b=a.split(" ");
    criteriaid+=b[1]+",";
    var bc,ac;
    ac=$(this).find("li:first").attr("class");
    bc=ac.split(" ");
    criteriaid+=bc[1]+"|";
    }*/
    });
    criteriaid=criteriaid.substr(0,criteriaid.length-1);
	pagesize=9999;
    productshow(typeid,criteriaid,lang,imgpath,1,'true')
    }
	
	function moreyear(){//news
	$(".tabNavi").show();
	}

    function showCountry(){
    if(document.getElementById("dropdown_country").style.display=="none")
    $('#dropdown_country').show();
    else{
    $('#dropdown_country').hide();
    $('#jsDropdownCountryMenu').hide();
    $('#jsDropdownLangMenu').hide();
    }
    }
    function selectCountry(){
    if(document.getElementById("jsDropdownCountryMenu").style.display=="none"){
    $('#jsDropdownCountryMenu').show();
    $('#jsDropdownLangMenu').hide();
    }
    else
    $('#jsDropdownCountryMenu').hide();
    }
    function selectLanguage(){
    if(document.getElementById("jsDropdownLangMenu").style.display=="none"){
    $('#jsDropdownLangMenu').show();
    }
    else
    $('#jsDropdownLangMenu').hide();
    }
    function change_list(country_name){
    $('#span_selectCountry').html(country_name);
    $('#jsDropdownCountryMenu').hide();

    var country_length=country.length;
    var add_string='',record=0;
    for (var i = 0; i <= country_length-1; i++) {
    if (country[i].name == country_name){

    add_string=add_string+'<li><a href="'+country[i].link+'"> '+country[i].version+' </a></li>';
    if(record==0)
    $('#span_selectVersion').html(country[i].version);
    record=record+1;
    }
    }
    $('#div_LangMenu').html(add_string);
    }                                                                     
	
	function promotion(){
	$("#promotion .imageContent").each(function(){
	var width=$(this).find("img").width();
	if(width>585)
	{
		$(this).find("img").css("width","585px");
	}
	});
	var promotiondet=$("#promotiondetail").find("img").width();
	if(promotiondet>890)
	$("#promotiondetail").find("img").css("width","890px");
	}
	
	function searchValueClear(id,value){
	
	$("#"+id).focus(function(){
		var currentvalue=$("#"+id).val();
		if(currentvalue==value)
		{
			$("#"+id).val('');
		}
		});
	$("#"+id).blur(function(){
		var currentvalue=$.trim($("#"+id).val());
		if(currentvalue=='')
		{
			$("#"+id).val(value);
		}
		});
	}
	
	function tipOpen( top, left, text )
	{
		try{
		// destroy any existing tooltips
		jQuery( '#container .genericTooltip' ).remove();

		// create tooltip
		//var tooltip = jQuery( '<div class="genericTooltip"><div class="top"></div><div class="content"></div><div class="bottom"></div></div>' );
		
		//if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) tooltip.css( { opacity:0 } );
		//tooltip.find( '.content' ).html( text );
		jQuery( '#container' ).append( '<div class="genericTooltip"><div class="top"></div><div class="content">'+text+'</div><div class="bottom"></div></div>'  );
		var tooltip=jQuery( '#container .genericTooltip' );
		// position
		//tooltip.css( { height:'auto' } );
		var height = tooltip.height();
		tooltip.css( { height:'0' } );
		//tooltip.css( { overflow:'hidden' } );
		top=top-height;
		tooltip.css( { top:top + 'px', left:left + 'px' } );
		//if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) setTimeout(function(){tooltip.animate( { top:top, height:height, opacity:1 }, 300, 'swing' )},3000);
		//else setTimeout(function(){tooltip.animate( { top:top, height:height }, 300, 'swing' )},3000);
		
		}
		catch(e){alert(e);}
	}
	
	function closed(){
	//if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) 
			//jQuery( '#container .genericTooltip' ).animate( { opacity:0 } ).queue( function() { jQuery( this ).remove() } );
	//else 
	jQuery( '#container .genericTooltip' ).remove();
	}
	
	
/*where to buy*/	
	function contentclose(obj){
$(obj).toggleClass("open");
$(obj).parent().find(".collapsibleContent").toggle();
}

function showdetail(obj,id){
$("#detailmenu .active").removeClass("active");
$(obj).addClass("active");
$(".detailgroup").hide();
$("#"+id).show();
}


function addressShow(bgid,containerid){
var heigth=$("#shell").height();
//var width=document.body.scrollWidth;

$("#"+bgid).height(heigth).show();
$("#"+containerid).show();
var companyCategoryId=$("#category").val();
$("#city_"+companyCategoryId).hide();
$("#city_").show();
$("#locationDetail").find("tbody").remove();
$("#companyOption").find("select").val('');
var allcompany=$("#allCompany").html();
$("#locationDetail").append(allcompany);
}

function addressHide(bgid,containerid){
$("#"+bgid).hide();
$("#"+containerid).hide();
}

function cityFilter(){
var category=$("#category").val();
$("select[name='city']").hide();
$("#city_"+category).show();

if(category=='')
{
	$("#locationDetail").find("tbody").remove();
	var allcompany=$("#allCompany").html();
	$("#locationDetail").append(allcompany);
}
else
{
	getDataInf(category,'');
}

}
	

	
	
