﻿$(document).ready(function () {
    var classToAdd = "";
    if ($.browser.msie) {
        classToAdd += "IE"
        if (jQuery.browser.version === "7.0") {
            classToAdd += " IE7";
        } else if (jQuery.browser.version === "8.0") {
            classToAdd += " IE8";
        } else if (jQuery.browser.version === "9.0") {
            classToAdd += " IE9";
        }
    } else if ($.browser.webkit) {
        classToAdd += "webkit"
    } else if ($.browser.opera) {
        classToAdd += "opera"
    } else if ($.browser.mozilla) {
        classToAdd += "mozilla"
    }

    $("body").addClass(classToAdd);

    $("#menu a:first-child").css("padding-right", "0");

    $("#nav a").each(function () {
        $(this).text("");
    });

    $(".news-item").each(function () {
        var height = 0;
        $(this).children().each(function () {
            if ($(this).outerHeight(true) > height) {
                height = $(this).outerHeight(true);
            }
        });

        $(this).height(height + 2);
    });

    $('#slideshow')
        .before('<div id="nav">')
        .cycle({
            fx: 'fade',
            timeout: 10000,
            pager: '#nav',
            //                height: 125,                
            pause: 1
        });

    $('#nav a').each(function () {
        $(this).html("<img src='/imgs/pager-image.png' />");
    });

    $('.products').cycle(
    {
        fx: 'fade',
        timeout: 10000,
        pause: 1
    });


    var uiTop =
    {
        easingType: 'easeOutQuart',
        containerID: 'toTop'
    };

    $("#toTop").click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    $(".placehoder").parent().children("input").keydown(function () {
        HandleLoginTextBox(this);
    });

    $(".placehoder").parent().children("input").keyup(function () {
        HandleLoginTextBox(this);
    });

    $(".placehoder").parent().children("input").blur(function () {
        HandleLoginTextBox(this);
    });

    $(".placehoder").click(function () {
        var elem = $(this);
        elem.hide();
        elem.parent().children("input").focus();
    });

    $("a[href='#']").click(function () {
        return false;
    });

    $("a[href='#']").each(function (e) {
        $(this).attr("href", "");
    });



});

$(window).load(function () {
    $(".placehoder").parent().children("input[type=text] ").each(function () {
        HandleLoginTextBox(this);
    });

    $(".placehoder").parent().children("input[type=password] ").each(function () {
        HandleLoginTextBox(this);
    });

    if ($("#toTop").length > 0) {
        var clientlogin = $(".ClientLogin");
        var totop = $("#toTop");

        var toAdd = 0;
        if($(".category-wrapper").length > 0) {
            toAdd = $(".category-wrapper").outerHeight(true);
        }

        if (clientlogin.position().top + clientlogin.outerHeight(true) + toAdd > $(".ProductSection, .CategorySection").outerHeight(true)) {
            totop.hide();
        }
    }
});

function HandleLoginTextBox(item) {
    var elem = $(item);
    if (elem.val() != "") {
        elem.parent().children(".placehoder").hide();
    } else {
        elem.parent().children(".placehoder").show();
    }
}
