﻿$(document).ready(function() {

    $("ul.TopMenuLeft li").hover(function() {
        if ($(this).find("div.TopMenuHidden").length) {
            $(this).find("div.TopMenuHidden").stop()
		    .animate({ left: "-" + (169 - $(this).find("a").width()) + "px" }, "fast")
		    .css("display", "block")

            var CssName = $(this).find("a:first").attr("class");
            if (CssName == 'TopMenuStartLinkWithDiv') {
                $(this).find("a:first").removeClass('TopMenuStartLinkWithDiv').addClass('TopMenuStartLinkWithDivOver');
            }
            else {
                $(this).find("a:first").removeClass('TopMenuLinkWithDiv').addClass('TopMenuLinkWithDivOver');
            }
            $(this).find("a:first").append("<span class='TopMenuRightCornerDiv' style='left:" + (24 + $(this).find("a:first").width()) + "px;'></span>");
            $(this).find("a:first").append("<span class='TopMenuLeftCornerDiv'></span>");
            $(this).find("div.TopMenuHidden").hover(function() { if ($(this).find("select").length) { $(this).find("select").hover(function() { return false; }) } })
        }

    }, function() {
        if ($(this).find("div.TopMenuHidden").length) {
            $(this).find("div.TopMenuHidden").stop()
		    .animate({ left: "-" + (169 - $(this).find("a").width()) + "px" }, "fast")
		    .css("display", "none")

            var CssName = $(this).find("a:first").attr("class");
            if (CssName == 'TopMenuStartLinkWithDivOver') {
                $(this).find("a:first").removeClass('TopMenuStartLinkWithDivOver').addClass('TopMenuStartLinkWithDiv');
            }
            else {
                $(this).find("a:first").removeClass('TopMenuLinkWithDivOver').addClass('TopMenuLinkWithDiv');
            }
            $(this).find("a:first").text($(this).find("a:first").text().replace("<span class='TopMenuRightCornerDiv' style='left:" + (24 + $(this).find("a:first").width()) + "px;'></span>", ""));
            $(this).find("a:first").text($(this).find("a:first").text().replace("<span class='TopMenuLeftCornerDiv'></span>", ""));
        }
    });
});

function RedirectToUrl(UrlToGo) {
    $(location).attr('href', UrlToGo);
}

function OpenNewInfo(NewsID) {
    $.fn.colorbox({ iframe: true, slideshow:false, innerWidth: 800, innerHeight: 600, href: 'ShowNewsContent.aspx?NewsID=' + NewsID, open: true });
}

function ShowAddOnImage(img, titleStr) {
    $.fn.colorbox({ href: img, open: true, title: titleStr });
}

function ShowColorBoxUrl(Url, titleStr, W, H) {
    $.fn.colorbox({ iframe: true, slideshow: false, innerWidth: W, innerHeight: H, href: Url, open: true, title: titleStr });
}

function ShowColorBoxUrlWithOpenerReload(Url, titleStr, W, H) {
    $.fn.colorbox({ iframe: true, slideshow: false, innerWidth: W, innerHeight: H, href: Url, open: true, title: titleStr, onClosed: function() { window.parent.location.reload(); } });
}

function ShowBuyReciveColorBox(Url, titleStr, W, H) {
    $.fn.colorbox({ iframe: true, slideshow: false, overlayClose: false, escKey: false, innerWidth: W, innerHeight: H, href: Url, open: true, title: titleStr, onClosed: function() { __doPostBack('ctl00$ContentMain$lnkLoadBasket', ''); } });
}

function AdvancePrices(saleType, divName) {
    if (saleType == '3') {
        document.getElementById(divName).style.display = 'none';
    }
    else {
        document.getElementById(divName).style.display = 'block';
    }
}

function AdvancedSearch(searchErr, siteUrl) {
    var search = $("[id$='_AdvenceSearchBox1_txtSearch']").val();

    if (search == "") { alert(searchErr); }
    else {
        var category = $("[id$='_AdvenceSearchBox1_ddCategory']").val();
        if (category == "" || isNaN(category) == true) { category = "0"; };

        var manufactor = $("[id$='_AdvenceSearchBox1_ddManufactor']").val();
        if (manufactor == "" || isNaN(manufactor) == true) { manufactor = "0"; };

        var saletype = $("[id$='_AdvenceSearchBox1_ddSaleType']").val();
        if (saletype == "" || isNaN(saletype) == true) { saletype = "0"; };

        var fromprice = $("[id$='_AdvenceSearchBox1_txtFromPrice']").val();
        if (fromprice == "" || isNaN(fromprice) == true || saleType == "3") { fromprice = "-1"; };

        var toprice = $("[id$='_AdvenceSearchBox1_txtToPrice']").val();
        if (toprice == "" || isNaN(toprice) == true || saleType == "3") { toprice = "-1"; };

        var url = siteUrl + "Search/2/" + category + "/" + manufactor + "/" + saletype + "/" + fromprice + "/" + toprice + "/1/0/" + search;

        RedirectToUrl(url);
        return false;
    }
}

function ShowHideDiv(divName) {
    if (document.getElementById(divName).style.display == 'none') {
        document.getElementById(divName).style.display = 'block';
    }
    else {
        document.getElementById(divName).style.display = 'none';
    }
}

function PrintCurrentDiv(urlMsg) {
    $.get(
             urlMsg,
             function(data) {
                 $('#PrintResults').html(data);
                 $("div#myPrintArea").printArea();
                 $('#PrintResults').html('');
             }
          );
}

         (function($) {
             $.fn.blink = function(options) {
                 var defaults = { delay: 600 };
                 var options = $.extend(defaults, options);

                 return this.each(function() {
                     var obj = $(this);
                     setInterval(function() {
                         if ($(obj).css("visibility") == "visible") {
                             $(obj).css('visibility', 'hidden');
                         }
                         else {
                             $(obj).css('visibility', 'visible');
                         }
                     }, options.delay);
                 });
             }
         } (jQuery))

