﻿$(function() {
    var x = $("#slideMenu").scrollable({
        size: 1,
        items: '#slideMenuItems',
        speed: 400
    });
    
    $('#slideMenu').height($('#firstPage').height());

    if (typeof (onLeftMenuInit) != 'undefined') {
        onLeftMenuInit();
    }
});

var g_sectionID;
var g_sectionUrlTitle;
function homeNextPage(sectionID, sectionUrlTitle)
{
    g_sectionID = sectionID;
    g_sectionUrlTitle = sectionUrlTitle
	$("#slideMenu").scrollable().next();
}


function gotoProductList(link, additionalParams)
{
	if(g_sectionID > 0)
	{
	    link = link.replace('[]', g_sectionID + additionalParams);
	    link = '/' + g_sectionUrlTitle + link; 
	    if (additionalParams != '')
	        link = link.replace('inventory', 'new-inventory');
        var api = $("#slideMenu").scrollable(); 
         
        api.getConf().onSeek = function() {         
            window.location.href = link;
        }
		api.next();
	}
}

function LeftMenuFastNext(id, stepCount) {
    if (!id)
        id = "slideMenu";
    var api = $("#" + id).scrollable();
    api.getConf().speed = 0;
    api.getConf().easing = null;
    fixHeight(1, id);
    if (!isNaN(stepCount)) {
        if (stepCount > 0) {
            for(var i=0; i <stepCount; i++)
                api.next();
        }
    }
    else
        api.next();
	api.getConf().speed = 400;
	api.getConf().easing = "swing";
}

function fixHeight(i, id, elemID) {
    if (!id)
        id = "slideMenu";
    var api = $("#" + id).scrollable();
    var h = 300;
    if (elemID != undefined)
        h = $('#' + id).height();
    else
        h = $(api.getItems()[api.getIndex() + i]).height();
    if (h < 300)
        h = 300;
    $('#' + id).height(h);
}


function slideAndGo(direction, url, nextPageID) {
    var api = $("#slideMenu").scrollable();

    if (direction < 0) {
        fixHeight(-1);

        api.prev(function() { window.location.href = url; });
    }
    else {
        if (nextPageID == '' || !nextPageID)
            nextPageID = "#secondPage";
        if ($("#zeroPage").length > 0) {
            $(nextPageID).html($("#zeroPage").html());
        }
        fixHeight(1);
        api.next(function() { window.location.href = url; });
        //api.next();
    }
    return false;


}
function moveToContent(contentDiv, targetPage, direction, url) {
    var api = $("#slideMenu").scrollable();
    targetPage.html(contentDiv.html());
    if (direction < 0) {
        fixHeight(-1);
        if (url != '' && url != undefined)
            api.prev(function() { window.location.href = url; });
        else
            api.prev();
    }
    else {
        fixHeight(1);
        if (url != '' && url != undefined) {
            api.next(function() { window.location.href = url; });
            //window.location.href = url;
        }
        else
            api.next();
    }
    return false;
}
