$(document).ready(function () {
    $("#background_img_wrap").height($("#wrapper").height());
    $(window).resize(function () {
        $("#background_img_wrap").height($("#wrapper").height());
        a()
    });
    $(window).load(function () {
        $("#bg_changer").css("left", -20 - $("#bg_changer").width())
    });
    $("#select1").sSelect();
    $(".scrollPane").jScrollPane();
    $(".tooltip").tooltip({
        showURL: false
    });
    $(".homeContentBox").addClass("closed");
    $(".homeContentBox .grey_box p").hide();
    $(".homeContentBox .grey_box").each(function () {
        $(this).find("p:first").show()
    });
    $(".homeContentBox .toggleBox").click(function () {
        $(this).parents(".homeContentBox").toggleClass("closed");
        if ($(this).parents(".homeContentBox").hasClass("closed")) {
            $(this).parents(".homeContentBox").find("p").hide();
            $(this).parents(".homeContentBox").find("p:first").show()
        } else {
            $(this).parents(".homeContentBox").find("p").slideDown()
        }
        return false
    });
    $("#primary-nav li").hover(function () {
        if ($(this).find(".scroll-pane").length > 0) {
            clearTimeout($(this).data("timeout"));
            sIFR.rollback("#primary-nav ul li#li-models > span");
            sIFR.rollback("#primary-nav ul li#li-models > p");
            primaryNavSifrAOver();
            primaryNavSifrPOver();
            $(this).addClass("active");
            $(this).find(".scroll-pane").show()
        }
    }, function () {
        if ($(this).find(".scroll-pane").length > 0) {
            var c = $(this);
            var d = setTimeout(function () {
                sIFR.rollback("#primary-nav ul li#li-models > span");
                sIFR.rollback("#primary-nav ul li#li-models > p");
                primaryNavSifrAOn();
                primaryNavSifrPOn();
                $(c).removeClass("active");
                $(c).find(".scroll-pane").hide()
            }, 600);
            $(this).data("timeout", d)
        }
    });
    a();

    function a() {
        var c = ($(window).width() - $("#wrapper").width()) / 2;
        if (c > 0) {
            $(".search-box-right").css({
                width: c,
                display: "block"
            })
        }
    }
    $("input[type=text]").focus(function () {
        if (this.value == this.defaultValue) {
            this.value = ""
        }
    });
    $("input[type=text]").blur(function () {
        if (this.value == "") {
            this.value = this.defaultValue
        }
    });
    $("#bg_changer a").click(function () {
        var c = $(this).attr("href");
        $("#background-img").hide();
        $("#background-img").attr("src", c);
        $("#background-img").fadeIn("slow");
        b();
        return false
    });
    $("#bg_changer-lnk").click(function () {
        $("#bg_changer").show();
        b();
        return false
    });

    function b() {
        var c = $("#bg_changer");
        c.animate({
            left: parseInt(c.css("left"), 20) == 0 ? -20 - c.outerWidth() : 0
        })
    }
    $(".showcase-list li>p").hide();
    if ($(".grayscale").length > 0) {
        $(window).load(function () {
            $(".grayscale").pixastic("desaturate")
        });
        $(".showcase-list li").hover(function () {
            $(this).find("p").slideDown();
            var c;
            if ($.browser.msie) {
                c = document.getElementById($(this).find("img").attr("id"))
            } else {
                c = document.getElementById($(this).find("canvas").attr("id"))
            }
            Pixastic.revert(c)
        }, function () {
            $(this).find("p").stop(true, true).hide();
            $(this).find("img").pixastic("desaturate")
        })
    }
    $("#contact-form label").labelOver("over")
});

$(function () {
    var c = $(".scroll-content ul", $(".scroll-pane")),
        b = $(".scroll-content ul li", $(".scroll-pane"));
    c.css("width", b.length * 330);
    var a = {
        max: (b.length * 330) - parseInt($(".scroll-content", $(".scroll-pane")).css("width")),
        slide: function (f, d) {
            c.css("left", "-" + d.value + "px")
        }
    };
});
jQuery.fn.labelOver = function (a) {
    return this.each(function () {
        var c = jQuery(this);
        var d = c.attr("for");
        if (d) {
            var b = jQuery("#" + d);
            this.hide = function () {
                c.css({
                    textIndent: -10000
                })
            };
            this.show = function () {
                if (b.val() == "") {
                    c.css({
                        textIndent: 0
                    })
                }
            };
            b.focus(this.hide);
            b.blur(this.show);
            c.addClass(a).click(function () {
                b.focus()
            });
            if (b.val() != "") {
                this.hide()
            }
        }
    })
};

function soundOff(a) {
    $(".icon-sound").toggleClass("soundoff");
    ytplayer = document.getElementById("myytplayer");
    if ($(".icon-sound").hasClass("soundoff")) {
        ytplayer.pauseVideo()
    } else {
        ytplayer.playVideo()
    }
}
function fullScreen() {
    window.open($(location).attr("href"), "mywindow", "status=0,toolbar=0,location=0,menubar=0,resizable=1,width=" + screen.availWidth + ",height=" + screen.availHeight);
    window.close()
}
var params = {
    allowScriptAccess: "always"
};
var atts = {
    id: "myytplayer"
};
swfobject.embedSWF("http://www.youtube.com/v/2qtg39ddNYE?enablejsapi=1&playerapiid=ytplayer&autoplay=1", "mysound", "1", "1", "8", null, null, params, atts);
