
function ShowHide(id)
{   
    divId = "#d" + id;
    lnkId = "#l" + id;
    if ($(divId).hasClass("hidden"))
    {
	    $(divId).slideDown("slow");
	    $(divId).removeClass("hidden");
	    $(lnkId).html("hide");
    } else 
    {
          $(divId).slideUp("slow");
          $(divId).addClass("hidden");
          $(lnkId).html("show more");  
    }
}

function DisplaySortingModeStatus(currentMode)
{
    if (currentMode == 0)     
    { 
        
        $("#sortByRating").removeClass("down_arrow");  
        $("#sortByBestsellers").removeClass("down_arrow");        
        $("#sortByPrice").removeClass("up_arrow");
        
        $("#sortByBestsellers").html('<a href="javascript:SetSortingMode(3)" >sort by bestsellers</a>'); 
        $("#sortByRating").html('<a href="javascript:SetSortingMode(2)" >sort by rating</a>');
        
        $("#sortByPrice").addClass("down_arrow"); 
        
     }
    else if (currentMode == 1)
    { 
        $("#sortByPrice").removeClass("down_arrow");
        $("#sortByPrice").addClass("up_arrow"); 
        
    }
    else if (currentMode == 2) 
    { 
        $("#sortByPrice").removeClass("down_arrow");
        $("#sortByPrice").removeClass("up_arrow");        
        $("#sortByBestsellers").removeClass("down_arrow");
       
        $("#sortByPrice").html('<a href="javascript:SetSortingMode(1)" >sort by price</a>');
        $("#sortByBestsellers").html('<a href="javascript:SetSortingMode(3)" >sort by bestsellers</a>');
        
        $("#sortByRating").addClass("down_arrow");         
        $("#sortByRating").html("sort by rating");
    }
    else if (currentMode == 3) 
    { 
        $("#sortByPrice").removeClass("down_arrow");
        $("#sortByPrice").removeClass("up_arrow");        
        $("#sortByRating").removeClass("down_arrow");  
        
        $("#sortByPrice").html('<a href="javascript:SetSortingMode(1)" >sort by price</a>');
        $("#sortByRating").html('<a href="javascript:SetSortingMode(2)" >sort by rating</a>');
              
        $("#sortByBestsellers").addClass("down_arrow"); 
        $("#sortByBestsellers").html("sort by bestsellers");
    }

}


function GetSortingMode()
{
    var sorting_arr = /\s*Sorting\s*=\s*(\d+)\s*;?/i.exec(document.cookie);
	if (sorting_arr != null && sorting_arr.length >= 2) 
	{
	    var SortingMode = sorting_arr[1];
	}

    if (SortingMode == null) SortingMode = 0;
    
    return SortingMode;
}

function SetSortingMode(SortingGroup)
{
    var currentSortingMode = GetSortingMode();
    var sortOrderChanged = false;
    switch (SortingGroup) 
    {
        case 1:
            if (currentSortingMode == 0) currentSortingMode = 1;
            else if (currentSortingMode == 1) currentSortingMode = 0;
            else currentSortingMode = 0;
            sortOrderChanged = true;
            break;
        case 2:
            if (currentSortingMode != 2)
            {
                currentSortingMode = 2;
                sortOrderChanged = true;
            }
            break;
        case 3:
            if (currentSortingMode != 3)
            {
                currentSortingMode = 3;
                sortOrderChanged = true;
            }
            break;
    }
    
    if (sortOrderChanged)
    {
    
        DisplaySortingModeStatus(currentSortingMode);
    
        var thisdomain_arr = /^[a-z0-9\-]*\.?([a-z0-9\-]+\.[a-z]+)$/i.exec(window.location.host);
	    if (thisdomain_arr != null && thisdomain_arr.length >= 2) var thisdomain = thisdomain_arr[1];
	    if (thisdomain == null) return;
	    
    
        document.cookie = "Sorting="+currentSortingMode+"; domain="+thisdomain+"; path=/";
        
        document.location.reload(false);
    }

}

function InitSortControl()
{
     var currentSortingMode = GetSortingMode();
     DisplaySortingModeStatus(currentSortingMode);
}





var cursor = 
     document.layers ? document.cursor :
     document.all ? document.all.cursor :
     document.getElementById ? document.getElementById('cursor') : null;
     
function cursor_wait() {
  $("body").append("<div>Loading...</div>");
}

function cursor_clear() {
  document.body.style.cursor = 'default';
}




// init
$(document).ready(function(){
    //$("body").append("<div class='pop_cont'><div id='loading'>Loading...</div></div>");
    //$("#loading").hide();

    //$("#loading").ajaxStart(function(){
    //   $(this).show();
    //});
    //$("#loading").ajaxStop(function(){
    //   $(this).hide();
    //});     
    
	InitSortControl();
});

