﻿var qsParm = new Array();

function getQuertParams()
{

    var fragments = window.location.href.split('/');

    qsParm["id"] = fragments[fragments.length - 1];
}

getQuertParams();

// Opening the menu by the current product
$("#propertiesMenu").ready(function(){
    if (qsParm["id"] != null)
    {
        // Finding all the hierarchy we need
        var propertie = $("#Properties a[dbId="+qsParm["id"]+"]");
        var subTypes = $("#SubTypes span[dbId="+propertie.attr("prntId")+"]");
        var types = $("#Types span[dbId="+subTypes.attr("prntId")+"]");

        // And then opening them one by one
        overTypes(types.get(0));
        overSubTypes(subTypes.get(0));
        overProperties(propertie.get(0));
    }
});



var timeOut;
function overTypes(obj, call_back)
{
    clearTimeout(timeOut);
    hideSubTypes();
    
    $("#SubTypes span").removeClass("active");
    $(obj).addClass("active");
    
    // Showing only the menus that their's parentID equals to the menu we hoovered
    $("#SubTypes span[prntId="+$(obj).attr("dbId")+"]").show();
    
    $("#SubTypes span:visible:first").addClass("active"); // Just lighting the first item in the second row (that's what they wanted...)
}


function overSubTypes(obj, call_back)
{
    clearTimeout(timeOut);
    hideProperties();
    
    $("#SubTypes span").removeClass("active");
    $("#Properties a").removeClass("active");
    $(obj).addClass("active");
    
    // Showing only the menus that their's parentID equals to the menu we hoovered
    $("#Properties a[prntId="+$(obj).attr("dbId")+"]").show();
    $("#Properties").css("right", pxRight(obj) +"px");
}


function overProperties(obj)
{
    clearTimeout(timeOut);
}

function outAll()
{    
    timeOut = setTimeout('hideSubTypes()', 2000);
}

/* Hide functions */
function hideSubTypes()
{
    $("#Types span").removeClass("active");
    $("#SubTypes span").hide();
    hideProperties();
}

function hideProperties()
{
    $("#Properties a").hide();
}


/* End of Hide functions */

// Calculates the distance from the span to the productsMenu
function pxRight(o)
{
    if(o == null)
    {
        return 0;
    }
    else
    {
        var x = 0;
        for(var i = 0; i<2; i++)
        {
            x+= (o.offsetParent.offsetWidth - o.offsetLeft) - o.offsetWidth;
            o = o.offsetParent;
        }
        return (x);
    }
}
