﻿//$(document).ready(function() {

//    //doTopMenuFix();
//	//$('#footercopy ul li:first-child').children().filter('a').addClass('first-meta');

//});

function doTopMenuFix() {

    var $mainMenu = $("#nav ul._level_1");
    var $subMenuToHide = $("#nav ul._level_2");
    
    $subMenuToHide.hide();
 

    var $subMenukids = $subMenuToHide.children();
    var $subMenuToFill = $("#subnav ul");
    var isSubMenuToFilled = false;

    $subMenukids.each(function(i) {
        $subMenuToFill.append('<li>' + this.innerHTML + '</li>');
        isSubMenuToFilled = true;
    });
 
    var subMenuToHideSelectedItems = $("#nav ul._level_2 .active").length;

   
    if (subMenuToHideSelectedItems) {
        $subMenuToHide.siblings().addClass("active");
        $subMenuToFill.prepend('<li><a href="' + getTopMenuSelectedHref() + '">View all</a></li>');
    }
    else {
        if (isSubMenuToFilled)
            $subMenuToFill.prepend('<li><a href="' + getTopMenuSelectedHref() + '" class="active">View all</a></li>');
    }
    $("#menu_holder").show();
}

function getTopMenuSelectedHref()
{
    return $("#nav ul._level_1 li a.active").attr("href")
}

function hideFirstItemInChain() {
    $("#wrap .wlock a:first").hide();
    $("#wrap .wlock span:first").hide();
}

function gotoProductSearch(url, defaultText) {
    var searchvalue = document.getElementById('searchfield').value;
    if (defaultText != searchvalue && searchvalue.length > 1)
        document.location.href = url + "?query=" + escape(searchvalue);    
    return false;
}

function focusProductSearch() {
    document.getElementById('searchfield').value = '';
}

function setNoHitsVisible() {
    $("div#no_hits").show();
}

function gotoProductLink() {
    var indexTmp = productLink.indexOf("href")
    var linkTmp = productLink.slice(indexTmp, productLink.length)

    indexTmp = linkTmp.indexOf(">")
    linkTmp = linkTmp.slice(6, indexTmp - 1);

    document.location.href = linkTmp;
}

function add_mychoice(id, url) {
    var img = ($('#fullframe a').children().eq(0).attr('src'));
    document.location.href = m_path_choice + '?add_id=' + id + '&add_img=' + escape(img) + '&add_url=' + escape(url)
}

function add_mychoice_check_ano(id, url, savePop) {

    var isColor = ($('#p_colors img.selected').length > 0); // ($('#specifications .list_color').get(0).selectedIndex > 0); //  
    var isSize = ($('#p_sizes img.selected').length > 0);  //($('#specifications .list_size').get(0).selectedIndex > 0); // 
    var img = ($('#fullframe a').children().eq(0).attr('src'));

    if (isSize && isColor) {

        var color = $('#p_colors img.selected').attr('title') + ' ' + $('#p_colors img.selected').attr('alt');  //$('#specifications .list_color').val();
        var size = $('#p_sizes img.selected').attr('title');  //$('#specifications .list_size').val();

        document.location.href = m_path_choice + '?add_id=' + id + '&color=' + escape(color) + '&size=' + escape(size) + '&add_img=' + escape(img) + '&add_url=' + escape(url) + '&save_pop=' + escape(savePop);
    }
    else
        document.location.href = m_path_choice + '?add_id=' + id + '&add_img=' + escape(img) + '&add_url=' + escape(url) + '&save_pop=' + escape(savePop);
}

function add_mychoice_check_ano_simple(id, url, index, savePop) {
    var img = $("#listwrapper ul li a img").eq(index).attr("src");
    document.location.href = m_path_choice + '?add_id=' + id + '&add_img=' + escape(img) + '&add_url=' + escape(url) + '&save_pop=' + savePop;
}

function productGo(endUrl, startUrl) {
    var url = new String(document.location.href);
    var start = url.slice(0, url.indexOf("/web/"));
    url = url.slice(url.indexOf("/web/") + 5, url.length);
    url = url.slice(0, url.indexOf("/"));
    url = "/web/" + url + endUrl;
    document.location.href = start + url;
    return false;
}

function fbs_click() { u = location.href; t = document.title; window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false; }

