 

/**

 * @author brian.lovely

 */

$().ready(function()
{	
    function showCurrentCountry()
    {		
        $(".store_locator_wrapper").css('display', 'none');

        var myVar = countrySelected;
       	
       	if(myVar == 'ca')
       	{
	     	$("#hide_results_wrapper").css("visibility", "hidden");
	    }
       	if(myVar == 'jp')
       	{
	     	$("#hide_results_wrapper").css("visibility", "hidden");
	     	$("#legendBugs").css("visibility", "hidden");
	    }	    

        if (myVar != 0) 
        {
        	//console.log("myVar: " + myVar);
            setAllTabs($("." + myVar));
            $("#" + myVar + "_wrapper").css('display', 'block');
            //$("#hide_results_wrapper").toggleClass("results_displayed");
			if(newSearch)
			{
				$("#" + myVar + "_wrapper").children(".sl_search_wrapper").css('display', 'block');
	          	$(".sl_results_wrapper").css('display', 'none');
	          	$(".china_store_locator").css('display', 'none');
			}
			else
			{	
            	$("#" + myVar + "_wrapper").children(".sl_search_wrapper").css('display', 'none');
          		$(".sl_results_wrapper").css('display', 'block');
          		if( (document.location.href.indexOf('countryCode=CN') != -1) || (document.location.href.indexOf('countryCode=HK') != -1) || (document.location.href.indexOf('countryCode=MO') != -1))
          		{
          			$(".china_store_locator").css('display', 'block');
          		}
			}
        } 
        else
        {
	        //console.log("defaulting to us");	        
	        $(".sl_results_wrapper").css('display', 'none');
	        $(".china_store_locator").css('display', 'none');
	        $("#us_wrapper").css('display', 'block');
	        $("#us_wrapper").children(".sl_search_wrapper").css('display', 'block');
		}
    }

    showCurrentCountry();   

   	if(document.getElementById('resultsSearch').style.display == 'block')
	{
		$("#hide_results_wrapper").css("visibility", "hidden");
	}
		

    function setTab(target, state)
    {
        var my_class = target.attr('class');

        var my_child = target.children();

        //Get tab's img into a variable

        var my_grandchild = my_child.children();

        var my_src_array = my_grandchild.attr('src').split("/");

        var my_src = "/" + my_src_array[1] + "/" + my_src_array[2] + "/" + my_src_array[3] + "/" + my_src_array[4] + "/" + state + "/" + my_src_array[6];

        my_grandchild.attr('src', my_src);
    }

    

    $("#sl_tabs li").click(function()
    {    	
		var myClass = $(this).attr('className');
		
    	if(myClass == 'ca')
	    	$("#hide_results_wrapper").css("visibility", "hidden");
	    else
	    	$("#hide_results_wrapper").css("visibility", "visible");
	    	    
	    //if(myClass != 'jp')
			setAllTabs($(this));
		
		//if(myClass != 'jp')
			$(".sl_results_wrapper").css('display','none');
	    
	    $(".china_store_locator").css('display', 'none');
        $("#" + myClass + "_wrapper").css('display', 'block');
        $("#" + myClass + "_wrapper").children(".sl_search_wrapper").css('display', 'block');
    });

    

    function setAllTabs(target)
    { 
        var my_parent = target.parent();

        //Turn all tabs off

        my_parent.children().each(function()
        {
            setTab($(this), "off");
        });

        //Turn current tab on
        	setTab(target, "on");

        //Find dividers on either side of current tab

        var olderSibling = target.prev(0);

        var youngerSibling = target.next(0);

        //...and flip them (checking first to see if they exist)

        if (olderSibling.length > 0) 
        {
        	setTab(olderSibling, "on");
        }

        if (youngerSibling.length > 0) 
        {
            setTab(youngerSibling, "on");
        }

        var my_class = target.attr('class');

		/*
		//dont show jp mapion iframe div if its not in jp tab 
		if(my_class != 'jp'){
			document.getElementById('JP_Mapion').style.display = 'none';
		}
		//if its in jp tab then only show mapion iframe div
		else {
			document.getElementById('JP_Mapion').style.display = 'block';	
		}
		*/
        var target_div = "#" + my_class + "_wrapper";

        $(".store_locator_wrapper").css("display", "none");

        $(target_div).css("display", "block");

    }

    

    $(".new_search a").click(function()
    {
        var my_id_array = $(this).attr('id').split('_');

        var my_id = my_id_array[0];

        var country_wrapper_id = my_id + "_wrapper";

        var country_wrapper = $("#" + country_wrapper_id);

        country_wrapper.children('.sl_search_wrapper').css("display", "block");

        country_wrapper.children('.sl_results_wrapper').css("display", "none");
        $(".china_store_locator").css('display', 'none');

    });   

});

function getResults(form)
{
	form.submit();
}

 

