/*-----------------------------------------------------------------------------
Web Site:			Ace Acoustics

CteatedDate:		14.05.2009
Autor:				AnnaG

LastChangedDate:	18.05.2009
LastChangedBy:		AnnaG
-----------------------------------------------------------------------------*/

jQuery(document).ready(function() {

    /* =Image preview by jQuery Tooltip
    ---------------------------------------- */
    jQuery(".img-shadow a").tooltip({
        track: true,
        delay: 0,
        fade: 250,
        showURL: false,
        bodyHandler: function() {
            return jQuery("<img />").attr("src", this.href);
        }
    });

    /* =Pseudo-pages
    ---------------------------------------- */
    var sHref = document.location.href.match(/.*#(.+)/);
    var PageID;

    if (sHref && jQuery(".page[rel*='" + sHref[1] + "']").length) {
        // show page with PageID -------------
        showPage(sHref[1]);

    } else {
        // hide all, show first --------------
        if (jQuery(".secondary-nav a.switch:first").attr("href")) {
            PageID = jQuery(".secondary-nav a.switch:first").attr("href").match(/#(.+)/)[1];
            showPage(PageID);
        }
    }

    // click on switch link  -----------------
    jQuery(".secondary-nav a.switch").bind("click", function(e) {
        var PageID = jQuery(this).attr("href").match(/#(.+)/)[1];
        showPage(PageID);
    });

});



/* =Show page for inner pseudo-pages
---------------------------------------- */
function showPage(PageID) {

// hide all, show page with PageID -----------
    jQuery(".page").each(function() {
        var jContent = jQuery(this);

        if (jContent.is("[rel*='" + PageID + "']")) {

            // show page
            jContent.queue(function() {
                jQuery(this).removeClass("hide");
                jQuery(this).dequeue();
            });

            // lunch gallery -----------------------------
            jContent.queue(function() {
                var jGallery = jQuery("#product-gallery-" + PageID);
                //alert(jGallery.length);
                
                if (jGallery.length && !jGallery.is(".jcarousel-list")) {
                    jGallery.jcarousel({
                        initCallback: productgallery_initCallback,
                        itemVisibleInCallback: {
                            onAfterAnimation: productgallery_itemVisibleInCallbackAfterAnimation
                        },
                        scroll: 1,
                        vertical: true,
                        pageid: PageID
                    });
                    //alert("Gallery " + PageID + " launched");
                }

                jQuery(this).dequeue();
            });


            // replace H2 & H1 --------------------------------
            SifrH1Replace();
            SifrH2Replace();

            // set current navigation item ---------------
            jQuery(".secondary-nav a.switch").parent().removeClass("current");
            jQuery(".secondary-nav a.switch[href*='" + PageID + "']").parent().addClass("current");

        } else {
            // hide page
            jContent.addClass("hide");
        }
    });
        
    return false;
}

/* =Callback functions for product gallery 
---------------------------------------- */
function productgallery_initCallback(carousel) {
    jQuery(".primary-image-gallery #" + carousel.options.pageid + "-control a").bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};
function productgallery_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state) {
    jQuery(".primary-image-gallery #" + carousel.options.pageid + "-control a").each(function() {
        if (jQuery(this).is(":contains('" + idx + "')")) {
            jQuery(this).parent().addClass("current");
        } else {
            jQuery(this).parent().removeClass("current");
        }
    });
};

/* =SIFR replace for H2 
---------------------------------------- */
function SifrH2Replace() {
    sIFR.replace(interstate_regular, {
        selector: 'h2'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #175999; font-size: 20px; text-align: left; leading: -2;}'
            , 'strong { color: #424242; font-size: 75%; }'
            , 'a { text-decoration: none }'
            , 'a:link { color: #175999 }'
            , 'a:hover { color: #175999 }'
        ]
    });
}

/* =SIFR replace for H1 
---------------------------------------- */
function SifrH1Replace() {
    sIFR.replace(interstate_regular, {
        selector: 'h1:not(.logo), .h1'
        , forceWidth: 'true'
        , wmode: 'transparent'
        , css: [
            '.sIFR-root { color: #175999; font-size: 24px; text-align: left; leading: -2;}'
            , 'a { text-decoration: none }'
            , 'a:link { color: #175999 }'
            , 'a:hover { color: #175999 }'
        ]
    });
}


