/// <reference path="jquery-1.4.4-vsdoc.js" />

/// <reference path="unoptimized/jquery.colorbox-min.js" />

/// <reference path="unoptimized/jquery.tinycarousel.js" />
/// <reference path="unoptimized/jquery-1.4.4.min.js" />

$(function() {
    ///====================================================================////
    ///DEBUG ONLY START
    ///====================================================================////
    //UNASSIGNED LINK CHECK
    //$('a[href=""]').css('border', '1px solid red');

    ///====================================================================////
    ///DEBUG ONLY END
    ///====================================================================////
    //integration kit video
    $('a.i-vid').colorbox({ close: "", iframe: true, innerWidth: 900, innerHeight: 595 });
   $('a.if-vid').colorbox({iframe:true, width:640, height:390});

    $('#carousel').jcarousel();
    //$("#secondary-nav").fadeTo(0, .8);
    $("#secondary-nav li a").prepend(" &raquo; ")
    $('#designSlider').tinycarousel({
        controls: false,
        pager: true,
        animation: false
    });

    $('#color-select li a.show').live('click', function(e) {
        e.preventDefault()
        $('#color-select li').removeClass('active');
        $(this).parent().addClass('active');
        $('#exterior,#interior').hide();
        $('#' + $(this).text()).show('fast');
    });
    $('#slider-code').tinycarousel({ controls: false, duration: 600, pager: true, interval: true });

    $("#header ul li").not('#header ul li.search, #header ul li.dealer, #header ul ul li').hover(function() {

        $(this).addClass("hover");
        $('ul:first', this).css('visibility', 'visible');

    }, function() {

        $(this).removeClass("hover");
        $('ul:first', this).css('visibility', 'hidden');

    });

    /* Technical Specification open/close toggle icon */
    $('h4.expand span').addClass('showTech');
    $('ul.specs').hide();

    $(function() {
        $('h4.expand').click(function() {
            $(this).next().slideToggle('slow', function() {
            });
            $(this).find('span').toggleClass('hideTech')
        });
    });

    /*IPHONE KIT TABS	*/
    $(function() {
        $("#i-kit ul#vehNav").tabs('#maincontent > div');
        $("#i-kit ul.app-nav").tabs('.tabs > div');
        $("#i-kit #iphone-features ul.pager").tabs('ul.overview > li');
    });
    //========================================================//
    //COLORS -START
    //========================================================//

    $('#body-color li').live('click', function() {

        $('#body-color li').removeClass('active');
        $(this).addClass('active');
        $('#hidden-body-color').val($('img', this).attr('alt'));
        setColors();
    });
    $('#tridion-color li').live('click', function() {
        $('#tridion-color li').removeClass('active');
        $(this).addClass('active');
        $('#hidden-tridion-color').val($('img', this).attr('alt'));
        setColors();
    });

    function setColors() {

        var newClass = $('#hidden-model-name').val() + '-' + $('#hidden-body-color').val() + '-' + $('#hidden-tridion-color').val();
        $('#stage').animate({ opacity: 0 }, 'fast', function() {
            $(this).removeClass($(this).attr('class'))
            .animate({ opacity: 1 })
            .addClass(newClass);
        });
    }
    //========================================================//
    //COLORS - END
    //========================================================//



    $("#header ul li ul li a").prepend(" &raquo; ");
    $("ul#vehNav li a").prepend(" &raquo; ");
    $("#quikLink ul li a").prepend(" &raquo; ");
    var cboxOptions = { scrolling: false, close: "" };
    $('a[href*="colors.aspx"]').colorbox($.extend({ onComplete: function() {
        $('#exterior').tinycarousel({ controls: false, pager: true, animation: false });
        $('#interior').tinycarousel({ controls: false, pager: true, animation: false });
        $('#interior').hide();
        $.colorbox.resize();
    }
    }, cboxOptions));
    $('a[href*="options.aspx"]').colorbox($.extend({
        onComplete: function() {
            $('#gallery').galleryView({
                panel_width: 800,
                panel_height: 240,
                frame_width: 180,
                frame_height: 100,
                pause_on_hover: true,
                easing: 'linear',
                nav_theme: 'dark'
            });
            $.colorbox.resize();
        }
    }, cboxOptions));
    $('a[href*="photo-gallery.aspx"]').colorbox($.extend({
        onComplete: function() {
            $('#gallery').galleryView({
                panel_width: 800,
                panel_height: 350,
                frame_width: 175,
                frame_height: 100,
                pause_on_hover: true,
                transition_speed: 400,
                easing: 'linear',
                nav_theme: 'dark',
                overlay_position: 'top'
            });
            $.colorbox.resize();
        }

    }, cboxOptions));
    $('a[href*="accessories.aspx"]').colorbox($.extend({
        onComplete: function() {

            $('#gallery').galleryView({
                panel_width: 800,
                panel_height: 200,
                frame_width: 175,
                frame_height: 100,
                pause_on_hover: true,
                easing: 'linear',
                nav_theme: 'dark'
            });
            $.colorbox.resize()
        }
    }, cboxOptions));
    ///Used for "more..." section in specifications
    /*$('ul.specs').hide();
    $('h4.expand').click(function() {
    $(this).next().slideToggle('slow', function() {
    });
    });
    */
    ///top-right close corner close colorbox
    $('#cboxTopRight').live('click', function() {
        $.colorbox.close();
    });
    ///LEAVE HASH FOR LAST BECAUSE IT USES TRIGGER TO KICK OFF ANY BOUND BEHAVIOR
    var hash = window.location.hash;
    if (hash) {
        if (hash == '#colors') {
            $('a[href*="colors.aspx"]').trigger('click');
        }
        if (hash == '#photos') {
            $('a[href*="photo-gallery.aspx"]').trigger('click');
        }
    }

});

//iphone kit FAQ show/hide
$(function() {
 	$("#app-faqs p").hide();
	$("#app-faqs h5").click(function() { 
  	$(this).next().slideToggle('slow');	
   });
  });
 
//electric drive  FAQ show/hide
$(function() {
 	$("#e-faqs p").hide();
	$("#e-faqs h4").click(function() { 
  	$(this).next().slideToggle('slow');	
   });
  });
 


function setStage(index) {
    $('#stage').empty().append($('#panels div.panel-content').eq(index).clone());
}

