Cufon.replace('.helvetica', { fontFamily: 'Helvetica Neue' });
Cufon.replace('.gotham-bold', { fontFamily: 'Gotham Bold' });
Cufon.replace('.gotham-medium', { fontFamily: 'Gotham Medium' });
Cufon.replace('.gotham-book', { fontFamily: 'Gotham Book' });

$(document).ready(function () {

    // slider show/hide
    $('.slider-show_hide').click(function () {
        var slider = $("#slider");
        var slidershow = $("#slider-show");
        var sliderhide = $("#slider-hide");
        if (slider.is(":visible")) {
            slidershow.css('display', 'block');
            sliderhide.css('display', 'none');
            $("#slider-wrapper").css('padding', '0');
            slider.slideUp();
            $.cookie("slider", "hide", { expires: 365 });
        } else {
            slidershow.css('display', 'none');
            sliderhide.css('display', 'block');
            $("#slider-wrapper").css('padding', '23px 0 0 0');
            slider.slideDown(function () {

            });
            $.cookie("slider", "show", { expires: 365 });
        }
    });

    if ($.cookie("slider")) {
        var slider = $.cookie("slider");
        if ($.cookie("slider") == "show") {
            $("#slider").css('display', 'block');
            $("#slider-show").css('display', 'none');
            $("#slider-hide").css('display', 'block');
        } else {
            $("#slider").css('display', 'none');
            $("#slider-wrapper").css('padding', '0');
            $("#slider-show").css('display', 'block');
            $("#slider-hide").css('display', 'none');
        }
    }

    // slider
    width = $("#slider").css('width');
    height = $("#slider").css('height');

    if ($("#hidAutoSlider").size() == 1 && $("#hidAutoSlider").val() == "1") {
        $("#slider").jFlow({
            slides: "#slides",
            width: width,
            height: height,
            auto: true
        });
    }
    else {
        $("#slider").jFlow({
            slides: "#slides",
            width: width,
            height: height
        });
    }

    // site colors show/hide  
    $('#site-colors-show_hide').click(function () {
        var colors = $("#site-colors-content");
        if (colors.is(":visible")) {
            colors.slideUp();
            $.cookie("colors", "hide", { expires: 365 });
        } else {
            colors.slideDown();
            $('html, body').animate({
                scrollTop: $("#page-switch").offset().top
            }, 1000);
            $.cookie("colors", "show", { expires: 365 });
        }
    });

    if ($.cookie("colors")) {
        var colors = $.cookie("colors");
        if ($.cookie("colors") == "show") {
            $("#site-colors-content").css('display', 'block');
        } else {
            $("#site-colors-content").css('display', 'none');
        }
    }

    // site colors
    $('#site-colors-content li a').click(function () {
        var color = $(this).attr('rel');
        $.cookie("color", color, { expires: 365 });
        $('#color-01').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-01.png)');
        $('#color-02').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-02.png) left');
        $('#color-03').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-03.png)');
        $('#color-04').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-04.png)');
        $('#color-05').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-05.png) right');
        $('#color-06').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-06.png)');
        $('#color-07').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-07.png)');
        $('#color-08').css('background', 'url(/img/colors/' + (color) + '/' + (color) + '-08.png)');
    });

    if ($.cookie("color")) {
        var cookie_color = $.cookie("color");
        //                var hidColor = $("#ctl00_Slider1_hidColor");
        //                if (hidColor != null && hidColor.val() != "") {
        //                    cookie_color = hidColor.val();
        //                }
        $('#color-01').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-01.png)');
        $('#color-02').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-02.png) left');
        $('#color-03').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-03.png)');
        $('#color-04').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-04.png)');
        $('#color-05').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-05.png) right');
        $('#color-06').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-06.png)');
        $('#color-07').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-07.png)');
        $('#color-08').css('background', 'url(/img/colors/' + (cookie_color) + '/' + (cookie_color) + '-08.png)');
    } else {
        var default_color = '67_baracuda';
        var hidColor = $("#ctl00_Slider1_hidColor");
        if (hidColor != null && hidColor.val() != "") {
            default_color = hidColor.val();
        }
        $('#color-01').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-01.png)');
        $('#color-02').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-02.png) left');
        $('#color-03').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-03.png)');
        $('#color-04').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-04.png)');
        $('#color-05').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-05.png) right');
        $('#color-06').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-06.png)');
        $('#color-07').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-07.png)');
        $('#color-08').css('background', 'url(/img/colors/' + (default_color) + '/' + (default_color) + '-08.png)');
    }

    // popups
    $("a[rel='work']").click(function () {
        $("#cboxOverlay").css("background", "#161615");
        $("#cboxContent").css("margin-top", "30px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading1.gif)");
        $("#cboxClose").css({ "top": "-20px", "right": "1px", "background-image": "url(/img/colorbox/close1.png)" });
        $(this).colorbox({ width: "920px", height: "2500px" });
    });

    $("a[rel='blog']").click(function () {
        $("#cboxOverlay").css("background", "#fefef5");
        $("#cboxContent").css("margin-top", "13px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading2.gif)");
        $("#cboxClose").css({ "top": "-3px", "right": "9px", "background-image": "url(/img/colorbox/close2.png)" });
        $(this).colorbox({ width: "920px", height: "2550px" });
    });

    $("a[rel='contact']").click(function () {
        $("#cboxOverlay").css("background", "#fefef5");
        $("#cboxContent").css("margin-top", "30px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading2.gif)");
        $("#cboxClose").css({ "top": "-20px", "right": "5px", "background-image": "url(/img/colorbox/close2.png)" });
        $(this).colorbox({ width: "920px", height: "1500px" });
    });

    // ajax
    $('#cboxLoadedContent a[rel="ajax"]').live('click', function (e) {
        e.preventDefault();
        var url = $(this).attr('href');
        $.ajax({
            type: 'GET',
            url: url,
            dataType: 'html',
            cache: true,
            beforeSend: function () {
                $('#cboxLoadedContent').empty();
                $('#cboxLoadingGraphic').show();
            },
            complete: function () {
                $('#cboxLoadingGraphic').hide();
            },
            success: function (data) {
                $('#cboxLoadedContent').append(data);
            }
        });
    });

    // gallery
    $("a[rel='gallery-dark']").click(function () {
        $("#cboxOverlay").css("background", "#161615");
        $("#cboxContent").css("margin-top", "58px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading1.gif)");
        $("#cboxClose").css({ "top": "-48px", "right": "16px", "background-image": "url(/img/colorbox/close1.png)" });
        $("#cboxPrevious").css({ "background-image": "url(/img/slider-arrows.png)" });
        $("#cboxNext").css({ "background-image": "url(/img/slider-arrows.png)" });
        $('#cboxContent').append("<div id='gallery-corner-1' class='gallery-corner-dark'></div>");
        $('#cboxContent').append("<div id='gallery-corner-2' class='gallery-corner-dark'></div>");
        $('#cboxContent').append("<div id='gallery-corner-3' class='gallery-corner-dark'></div>");
        $('#cboxContent').append("<div id='gallery-corner-4' class='gallery-corner-dark'></div>");
        $("a[rel='gallery-dark']").colorbox({ transition: "fade", opacity: 1 });
        $("#cboxPrevious").css({ "display": "block" });
        $("#cboxNext").css({ "display": "block" });
        $("#cboxClose").click(function () {
            $('#gallery-corner-1').remove();
            $('#gallery-corner-2').remove();
            $('#gallery-corner-3').remove();
            $('#gallery-corner-4').remove();
        });
    });

    $("a[rel='gallery-light']").click(function () {
        $("#cboxOverlay").css("background", "#fffef8");
        $("#cboxContent").css("margin-top", "58px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading2.gif)");
        $("#cboxClose").css({ "top": "-48px", "right": "16px", "background-image": "url(/img/colorbox/close2.png)" });
        $("#cboxPrevious").css({ "background-image": "url(/img/slider-arrows2.png)" });
        $("#cboxNext").css({ "background-image": "url(/img/slider-arrows2.png)" });
        $('#cboxContent').append("<div id='gallery-corner-1' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-2' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-3' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-4' class='gallery-corner-light'></div>");
        $("a[rel='gallery-light']").colorbox({ transition: "fade", opacity: 1 });
        $("#cboxPrevious").css({ "display": "block" });
        $("#cboxNext").css({ "display": "block" });
        $("#cboxClose").click(function () {
            $('#gallery-corner-1').remove();
            $('#gallery-corner-2').remove();
            $('#gallery-corner-3').remove();
            $('#gallery-corner-4').remove();
        });
    });

    $("a[rel='gallery-sidelight']").click(function () {
        $("#cboxOverlay").css("background", "#fffef8");
        $("#cboxContent").css("margin-top", "58px");
        $("#cboxLoadingGraphic").css("background-image", "url(/img/colorbox/loading2.gif)");
        $("#cboxClose").css({ "top": "-48px", "right": "16px", "background-image": "url(/img/colorbox/close2.png)" });
        $("#cboxPrevious").css({ "background-image": "url(/img/slider-arrows2.png)" });
        $("#cboxNext").css({ "background-image": "url(/img/slider-arrows2.png)" });
        $('#cboxContent').append("<div id='gallery-corner-1' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-2' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-3' class='gallery-corner-light'></div>");
        $('#cboxContent').append("<div id='gallery-corner-4' class='gallery-corner-light'></div>");
        $("a[rel='gallery-sidelight']").colorbox({ transition: "fade", opacity: 1 });
        $("#cboxPrevious").css({ "display": "block" });
        $("#cboxNext").css({ "display": "block" });
        $("#cboxClose").click(function () {
            $('#gallery-corner-1').remove();
            $('#gallery-corner-2').remove();
            $('#gallery-corner-3').remove();
            $('#gallery-corner-4').remove();
        });
    });

    // page share
    $(".a-share_this_page").click(function () {
        $("#page-email").hide();
        $("#page-share").toggle();
    });

    // page email
    $(".a-email_this_page").click(function () {
        $("#page-share").hide();
        $("#page-email").toggle();
    });

    // tooltip
    $(".tooltip").easyTooltip();

    // window resize
    $(window).resize(function () {
        var width = $("#slider").css('width');
        $("#jFlowSlide, .jFlowSlideContainer").css('width', width);
        var div_number = $("#slides > div").size();
        var width = (($("#slider").width()) * div_number) + "px";
        $("#slides").css('width', width);
        var width = $("#slider").width();
        var selected = $(".jFlowSelected").attr('id');
        var margin = -(selected - 1) * width + "px";
        $("#slides").css('margin-left', margin);

        var width = Math.round(((($(window).width()) / 2) + 27)) + "px";
        $('#color-02').css('width', width);
        var width = Math.round(((($(window).width()) / 2) - 280)) + "px";
        $('#color-05').css('width', width);
        var width = Math.round(((($(window).width()) / 2) - 277)) + "px";
        $('#color-06').css('left', width);
        var width = Math.round(((($(window).width()) / 2) - 509)) + "px";
        $('#header-left, #header-right').css('width', width);
        var width = Math.round(((($(window).width()) / 2) - 304)) + "px";
        $('#stripe-left').css('width', width);
        var width = Math.round(((($(window).width()) / 2) - 301)) + "px";
        $('#stripe-right').css('left', width);
        var width = Math.round(((($(window).width()) / 2) - 207)) + "px";
        $('#stripe-title-left').css('width', width);
        var width = Math.round(((($(window).width()) / 2) - 207)) + "px";
        $('#stripe-title-center').css('left', width);
        var width = Math.round(((($(window).width()) / 2) - 60)) + "px";
        $('#stripe-title-right').css('width', width);
    });

    // color width
    var width = Math.round(((($(window).width()) / 2) + 27)) + "px";
    $('#color-02').css('width', width);

    var width = Math.round(((($(window).width()) / 2) - 280)) + "px";
    $('#color-05').css('width', width);

    var width = Math.round(((($(window).width()) / 2) - 277)) + "px";
    $('#color-06').css('left', width);

    // header width
    var width = Math.round(((($(window).width()) / 2) - 509)) + "px";
    $('#header-left, #header-right').css('width', width);

    // stripe width
    var width = Math.round(((($(window).width()) / 2) - 304)) + "px";
    $('#stripe-left').css('width', width);

    var width = Math.round(((($(window).width()) / 2) - 301)) + "px";
    $('#stripe-right').css('left', width);

    var width = Math.round(((($(window).width()) / 2) - 207)) + "px";
    $('#stripe-title-left').css('width', width);

    var width = Math.round(((($(window).width()) / 2) - 207)) + "px";
    $('#stripe-title-center').css('left', width);

    var width = Math.round(((($(window).width()) / 2) - 60)) + "px";
    $('#stripe-title-right').css('width', width);

    // default input value
    $('input, textarea').focus(function () {
        if ($(this).val() == $(this).attr('defaultValue')) {
            $(this).val('');
        }
    });
    $('input, textarea').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('defaultValue'));
        }
    });

});
