/*  GUI     */
//  Load just after the DOM - for Mozilla browsers
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

//  For other browsers
window.onload   =   init;

function    init()
{
    //  Load only once
    if (arguments.callee.done) return;
    arguments.callee.done = true;
    
    set_external_links();
    set_active_menu_options('mainnav');
    preload_items();
}

function        set_external_links()
{
    //  Set external links to blank target && standards compliant
    if(document.getElementsByTagName)
    {
        var anchors =   document.getElementsByTagName('a');
        for(var i = 0;i<anchors.length;i++)
        {
            var anchor  =   anchors[i];
            if(anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external')
            {
                anchor.title    =   anchor.title + ' (a new window will open)';
                anchor.target   =   '_blank';
            }
        }
    }
}

function    set_active_menu_options(obj)
{
    var current_href    =   document.location.pathname;
    var current_href_s  =   current_href+'/';
    
    /*  IE takes a_href absolute..  */
    var host            =   'http://'+document.location.hostname;
    
    var menu            =   document.getElementById(obj);
    if(menu)
    {
        var as              =   menu.getElementsByTagName('a');   
        for(var i=0;i<as.length;i++)
        {
            var a_href      =   as[i].getAttribute('href');
            a_href          =   a_href.replace(host,'');
            var a_href_s    =   a_href+'/';
            if(current_href == a_href || current_href_s == a_href || current_href == a_href_s || current_href_s == a_href_s || current_href.indexOf(a_href) !== -1)
            {
                if(a_href != '/')
                    as[i].className =   'active';
            }
        }
    }
}

function        preload_items()
{
    //  Preload items
    var img     =   new Image();
    img.src     =   '/images/_shirts/set2.png';
    var img2    =   new Image();
    img2.src    =   '/images/_shirts/set3.png';
}

jQuery(document).ready(function(){
    if (jQuery('#visual').length) { 
        jQuery('#visual > ul').innerfade({
                            speed: 2000,
                            timeout: 5000,
                            type: 'sequence',
                            containerheight: '353px'
                        });
    }
    jQuery(function(){
       if (jQuery('#carousel_wrapper').length) { 
           jQuery("#carousel_wrapper").carousel( {
                            autoSlide: true,
                            dispItems: 4,
                            loop: true,
                            nextBtn: "<a title='next'>next</a>",
                            prevBtn: "<a title='previous'>previous</a>",
                            prevBtnInsert: "appendTo",
                            autoSlideInterval: 6000   
            });
       }
    });
});
