/**
 * bassgrinder [a] gmail
 * 2009oct08
 */
 
$(function(){
    $("div.tabbed_area a.tab1").click(function () {
        if ( $(this).attr('class') == 'tab1 active' ) return false;
        $("ul.tabs a.active").removeClass("active");
        $(this).addClass("active");
        $("div.tabbed_area div.content").hide();
        var content_show = $(this).attr("rel");
        $("#"+content_show).show();
        return false;
    });
    setTimeout('krjs.hideNotifs()', 5000);
    $("a.model-info-button").each(function(){
        $(this).click(function(){
            if ( ! $(this).hasClass('open')) {
                $(this).addClass('open').parent().find('div').slideDown('fast');
            } else {
                $(this).removeClass('open').parent().find('div').slideUp('fast');
            }
            return false;
        });
    });
});


var krjs = {
    flashMovieScript: function(movie, width, height){
        document.write('<div>');
        document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+ width +'" height="'+ height +'">\n');
    	document.write('<param name="movie" value="'+ movie +'" />\n');
    	document.write('<PARAM NAME="wmode" VALUE="transparent">\n');
    	document.write('<param name="quality" value="high" />\n');
    	document.write('<embed src="'+ movie +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+ width +'" height="'+ height +'" wmode="transparent"></embed>\n');
    	document.write('</object>\n');
    	document.write('</div>');
    },
    spotRequiredField: function(obj){
        $(obj).css('borderColor', '#f00');
        $(obj).focus();
    },
    validateEmail: function(form_id,email) {
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = document.forms[form_id].elements[email].value;
        if(reg.test(address) == false) {
            return false;
        }
        return true;
    },
    hideNotifs: function(){
        $('p.alerts-notif').fadeOut('slow', 0);
    },
    toggleDefVal: function(obj, def, onblur){
        if (onblur){if(obj.val()=='')obj.val(def);}
        else if (obj.val()==def)obj.val('');        
    },

}


$(function(){

kr = {
    wrapper: 'div.featured_wrapper',
    timer: null,
    active: null,
    next: null,
    moveNext:function(){
        this._stopTimer();
        this.slideShow();
        this.enableTimer();
    },
    movePrevious:function(){
        this._stopTimer();
        this.slideShowReverse();
        this.enableTimer();
    },
    slideShow:function(){
        var $active = $(this.wrapper+' DIV.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' DIV:last');
        this.next = $active.next().length ? $active.next() : $(this.wrapper+' DIV:first');
        this.active = $active;
        this._animate();
    },
    slideShowReverse:function(){
        var $active = $(this.wrapper+' DIV.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' DIV:last');
        this.next = $active.prev().attr('class')=='hidden' ? $active.prev() : $(this.wrapper+' DIV:last');
        this.active = $active;
        this._animate();
    },
    enableTimer:function(){
        kr.timer=setInterval( "kr.slideShow()", 12000 );
    },
    _animate:function(){
        var $active = this.active;
        var $next = this.next;
        $active.animate({opacity: 0.0}, 600, function() {
            $next.css({opacity: 0.0})
                .removeClass('hidden')
                .addClass('active')
                .animate({opacity: 1.0}, 600, function() {
                    $active.removeClass('active');
                    $active.addClass('hidden');
                });
            });
    },
    _stopTimer:function(){
        clearInterval(kr.timer);
        if (this.active) this.active.stop(true, true);
        if (this.next) this.next.stop(true, true);
    }

};


kr.enableTimer();
$(kr.wrapper+" a.featured_vehicle_link").click(function(){kr.moveNext();return false;});
//$(kr.wrapper+" span#button-up").click(function(){kr.movePrevious()});
//$(kr.wrapper+" span#button-down").click(function(){kr.moveNext()});

});


/*
    $(document).ready(function() {
    	$('.clicknclear').click(function() {
    		$(this).attr('rel', $(this).val());
    		$(this).val('');
    	}).blur(function() {
    		if ($(this).val().length < 1)
    			$(this).val($(this).attr('rel'));
    	});
    });
*/


$(function(){

rotator = {
    wrapper: 'div.head-rotator-wrapper',
    timer: null,
    active: null,
    next: null,
    moveNext:function(){
        this._stopTimer();
        this.slideShow();
        this.enableTimer();
    },
    movePrevious:function(){
        this._stopTimer();
        this.slideShowReverse();
        this.enableTimer();
    },
    slideShow:function(){
        var $active = $(this.wrapper+' p.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' p:last');
        this.next = $active.next().length ? $active.next() : $(this.wrapper+' p:first');
        this.active = $active;
        this._animate();
    },
    slideShowReverse:function(){
        var $active = $(this.wrapper+' p.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' p:last');
        this.next = $active.prev().attr('class')=='hidden' ? $active.prev() : $(this.wrapper+' p:last');
        this.active = $active;
        this._animate();
    },
    enableTimer:function(){
        rotator.timer=setInterval( "rotator.slideShow()", 10000 );
    },
    _animate:function(){
        var $active = this.active;
        var $next = this.next;
        $active.animate({opacity: 0.0}, 600, function() {
            $next.css({opacity: 0.0})
                .removeClass('hidden')
                .addClass('active')
                .animate({opacity: 1.0}, 600, function() {
                    $active.removeClass('active');
                    $active.addClass('hidden');
                });
            });
    },
    _stopTimer:function(){
        clearInterval(rotator.timer);
        if (this.active) this.active.stop(true, true);
        if (this.next) this.next.stop(true, true);
    }

};


if ( $(rotator.wrapper+' p').length > 1) {
    rotator.enableTimer();
    $(rotator.wrapper+" span#button-prev").click(function(){rotator.movePrevious()});
    $(rotator.wrapper+" span#button-next").click(function(){rotator.moveNext()});
} else {
    $(rotator.wrapper+" span#button-prev").remove();
    $(rotator.wrapper+" span#button-next").remove();
}


});