// JavaScript Document

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

$.fn.equals = function(compareTo) {
        if (!compareTo || !compareTo.length || this.length!=compareTo.length) 
{ 
                return false; 
        } 
        for (var i=0; i<this.length; i++) { 
                if (this[i]!==compareTo[i]) { 
                        return false; 
                } 
        } 
        return true; 



} 

$.fn.overlabel = function( options ) {
 
        // build main options before element iteration
        var opts = $.extend( {}, $.fn.overlabel.defaults, options );
 
        var selection = this.filter( 'label[for]' ).map( function() {
 
            var label = $( this );
            var id = label.attr( 'for' );
            var field = document.getElementById( id );
 
            if ( !field ) return;
 
            // build element specific options
            var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
 
            label.addClass( o.label_class );
 
            var hide_label = function() { label.css( o.hide_css ) };
            var show_label = function() { this.value || label.css( o.show_css ) };
 
            $( field )
                 .parent().addClass( o.wrapper_class ).end()
                 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
 
            return this;
 
        } );
 
        return opts.filter ? selection : selection.end();
    };
 
    // publicly accessible defaults
    $.fn.overlabel.defaults = {
 
        label_class:   'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css:      { 'text-indent': '-10000px' },
        show_css:      { 'text-indent': '0px', 'cursor': 'text' },
        filter:        false
 
    };


function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    if ( !$active.equals($next)) {
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
        }
}

$(document).ready(function() {
	$("#news").newsTicker();
	$("#accordion").accordion({ collapsible: true, active: false });
    setInterval( "slideSwitch()", 15000 );
   var randomNumCase = Math.floor(Math.random()*($('div#randomCase div').length));
   $('div#randomCase div:eq(' + randomNumCase + ')').css("display", "block");
   var randomNumProduct = Math.floor(Math.random()*($('div#randomProduct div').length));
   $('div#randomProduct div:eq(' + randomNumProduct + ')').css("display", "block");
   $("label.overlabel").overlabel();
   $('#menubar a')
		.css( {backgroundPosition: "0px 70px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-20px 188px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(80px 70px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0px 70px"})
			}})
		});

   initialize();

});

