﻿/// <reference path="jquery-1.4.3.min.js" />

function SearchSiteEvent(event) {
    xtn.fn.log([event.keyCode, event.which]);
    if (event.keyCode == 13) {
        event.preventDefault();
        var h = 'desktopdefault.aspx/tabid-4639/?cx=011820701077732867529:vgoktadmtxe&cof=FORID:9&ie=UTF-8&q=' + document.getElementById('search-query').value + '&sa=Search';
        document.location.href = h;
        $("form").submit(function () { return false; });
    }
}

$(document).ready(function () {

    $("#search-query").keydown(SearchSiteEvent);

    // auto-clear
    $("input.ui-auto-clear").each(function () {
        var i = $(this), v = i.attr('title');

        i.focus(function () {
            if ($(this).attr('title') == $(this).val()) $(this).removeClass("ui-auto-clear").val("");
        });

        i.blur(function () {
            if ($(this).val() == '') $(this).addClass("ui-auto-clear").val(v);
        });
    });

    $("div.ui-content-split div.ui-content-area:first").addClass("ui-content-area-left");

    $("ul.ui-content-list li.ui-content-area").each(function (indx) {
        xtn.fn.log("indx: " + indx);
        xtn.fn.log("modulo: " + (indx % 3));
        if (((indx + 1) % 3) == 0) $(this).addClass("ui-last");
    });

    $(document.body).addClass(xtn.fn.browser(false));

    var bxFade = $("ul.bx-fade").bxSlider({
        auto: true,
        mode: 'fade',
        speed: $.browser.msie ? 0 : 700,
        pause: 5000,
        controls: false,
        infiniteLoop: false,
        onLastSlide: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
            bxFade.stopShow();

            setTimeout(function () {
                var li = $(currentSlideHtmlObject);
                var h = $("h5", li);
                var ul = li.parent();

                var td = $("td.box-middle-center", li);
                td
                    .css({
                        height: (td.height() + 5) + 'px',
                        width: td.width() + 'px'
                    })

                h.insertBefore($("<div />").css("width", "595px"));

                $("h5", li).fadeOut(0);

                var fadeInSpeed = $.browser.msie ? 0 : 'slow';

                $("img", li).fadeOut('slow', function () {

                    $("li", ul).each(function (indx) {
                        if (indx != currentSlideNumber) {
                            var hn = $("<h5 />")
                                .addClass("font-caecilia")
                                .text($("img", this).attr("alt").replace("<br />   ", ""))
                                .css({ display: 'none' })
                                .insertBefore(h);
                            Cufon.refresh();
                            hn.delay(indx * 300).fadeIn(fadeInSpeed, function () { xtn.fn.log(['done', new Date().getTime()]); });
                        }
                    });
                    //if ($.browser.msie) Cufon.refresh();
                    $("h5", li).delay(currentSlideNumber * 300).fadeIn(fadeInSpeed);

                });
            }, 3000);
        }
    });

    var bxSlider = $("#ui-video-slider").bxSlider({
        auto: true,
        speed: 700,
        pause: 3000,
        infiniteLoop: true,
        displaySlideQty: 3,
        pager: false,
        wrapperClass: 'bx-video'
    });


    $("a[rel='fancybox-inline']").fancybox({ showNavArrows: false, showNavArrows: false, autoDimensions: true, centerOnScroll: true, overlayColor: '#000', overlayOpacity: 0.8, autoScale: true });

    $("a[rel='fancybox-iframe']").fancybox({ showNavArrows: false, width: 790, height: 585, type: 'iframe', autoScale: false, autoDimensions: true, centerOnScroll: true, overlayColor: '#000', overlayOpacity: 0.8 });

    $("a[rel^='fancybox-inline-']").click(function () {
        var d = $(this).attr("rel").replace('fancybox-inline-', '').split('x');
        $.fancybox({ autoDimensions: false, showNavArrows: false, width: parseInt(d[0]), height: parseInt(d[1]), centerOnScroll: true, overlayColor: '#000', overlayOpacity: 0.8, autoScale: false }, this);
        return false;
    });

    $("a[rel='coolzone-video']").fancybox({ width: 400, height: 350, showNavArrows: false, autoDimensions: true, centerOnScroll: true, overlayColor: '#000', overlayOpacity: 0.8, autoScale: true, type: 'swf' });

    $("a[rel^='fancybox-iframe-']").click(function () {
        var d = $(this).attr("rel").replace('fancybox-iframe-', '').split('x');
        $.fancybox({ type: 'iframe', autoScale: false, showNavArrows: false, width: parseInt(d[0]), height: parseInt(d[1]), padding: 0, autoDimensions: true, centerOnScroll: true, overlayColor: '#000', overlayOpacity: 0.8 }, this);
        return false;
    });
});

Cufon.replace('.font-caecilia', { fontFamily: 'caecilia', hover: true });

