jQuery(document).ready(function(){

	//SuperFish Dropdown Navigation
	jQuery("ul.sf-menu")
		.superfish({
		animation : { opacity:"show"}
	});	
	
	
	
    //jCarousel Plugin
    jQuery('#carousel').jcarousel({
        vertical: true,
        scroll: 1,
        auto: 15,
        wrap: 'circular',
		start: 0,
        initCallback: mycarousel_initCallback,
        itemLoadCallback: mycarousel_itemLoadCallback
    });


	//Front page Carousel - Initial Setup
   	jQuery('div#slideshow-carousel a img').css({'opacity': '0.5'});
   	jQuery('div#slideshow-carousel a img:first').css({'opacity': '1.0'});
   	jQuery('div#slideshow-carousel li a:first').append('<span class="arrow"></span>')

  
  	//Combine jCarousel with Image Display
    jQuery('div#slideshow-carousel li a').hover(
       	function () {
        		
       		if (!jQuery(this).has('span').length) {
        		jQuery('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
   	    		jQuery(this).stop(true, true).children('img').css({'opacity': '1.0'});
       		}		
       	},
       	function () {
        		
       		jQuery('div#slideshow-carousel li a img').stop(true, true).css({'opacity': '0.5'});
       		jQuery('div#slideshow-carousel li a').each(function () {
       			if (jQuery(this).has('span').length) $(this).children('img').css({'opacity': '1.0'});
       		});
       	}
	).click(function () {

	    jQuery('span.arrow').remove();        
		jQuery(this).append('<span class="arrow"></span>');
       	jQuery('div#slideshow-main li').removeClass('active');        
       	jQuery('div#slideshow-main li.' + $(this).attr('rel')).addClass('active');	
       	return false;
		
		
	});
	
	// Give active state to thumbnails
	jQuery("#carousel li a").click(function(event) {
		event.preventDefault();
		jQuery("#carousel li a.active").removeClass('active').addClass('');
		jQuery(this).removeClass('').addClass('active');
        

	});  

	// puts a strong tag in the div that dynamically prodcues the Up & Down arrows in the carousel
	jQuery(".jcarousel-next-vertical").html('<strong></strong>');
	jQuery(".jcarousel-next-vertical strong").mouseover(function(){
			jQuery(this).removeClass().addClass("ro");
		}).mouseout(function(){
			jQuery(this).removeClass().addClass("");		
		});

	jQuery(".jcarousel-prev-vertical").html('<strong></strong>');
	jQuery(".jcarousel-prev-vertical strong").mouseover(function(){
			jQuery(this).removeClass().addClass("ro");
		}).mouseout(function(){
			jQuery(this).removeClass().addClass("");		
		});



		// Twitter feed
		//Based on jquery.livetwitter.js: pulls up any searches that calls 90octanes and puts it into the tweetfeed jQuery('#twitter').liveTwitter('90octane', {limit: 2, rate: 5000});
		jQuery('#twitter').liveTwitter('90octane', {limit: 2, refresh: false, mode: 'user_timeline'});
/*	Based on jquery.twitter1.js
	jQuery("#twitter").tweet({
      //intro_text:"if you find it interesting that ",
      //outro_text: " then please, ",
      join_text: "auto",
      username: "90octane",
      count: 2,
      auto_join_text_default: "", 
      auto_join_text_ed: "",
      auto_join_text_ing: "",
      auto_join_text_reply: "we replied",
      auto_join_text_url: "",
      loading_text: "Loading tweets..."
	  
    });*/

		/*Based on jquery.twitter.js
		jQuery("#twitter").getTwitter({
					userName: "90octane",
					numTweets: 2,
					loaderText: "Loading tweets...",
					slideIn: false,
					showHeading: true,
					headingText: "Latest Tweets",
					showProfileLink: true
				});*/

 
	//Popup for the RSS Feed Description
	jQuery(".hopupRSS").colorbox({width:"735px", inline:true, href:"#inline_hopupRSS"});
 	//Popup for the Privacy Policy Description
	jQuery(".hopupPolicy").colorbox({width:"735px", inline:true, href:"#inline_hopupPolicy"});
	//Popup for the Terms of Use Description
	jQuery(".hopupTermsUse").colorbox({width:"735px", inline:true, href:"#inline_hopupTermsUse"});


//Fade Effect 
	jQuery(".fade span").css("opacity","0");
		jQuery(".fade span").hover(
			function () {
			jQuery(this).stop().animate({
			opacity: 1
			}, "slow");
		}, 
		function () {
			jQuery(this).stop().animate({
			opacity: 0
			}, "slow");
		}
	);

// sequences
var kkeys = [], kon = "38,38,40,40,37,39,37,39,66,65";
	jQuery(document).keydown(function(e) {
	  kkeys.push(e.keyCode);
	  if(kkeys.toString().indexOf(kon) >= 0 ){
		jQuery(document).unbind('keydown',arguments.callee);
			jQuery('<div id="special" style="width:642px; height:482px;"><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="640" height="480"><param name="movie" value="http://www.90octane.com/assets/90octane/swf/Robot_Unicorn_Attack.swf"><param name="quality" value="high"></param><param name="menu" value="false"></param><embed src="http://www.90octane.com/assets/90octane/swf/Robot_Unicorn_Attack.swf" width="640" height="480" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false"></embed></object></div>').insertAfter('#container').fadeIn(1000);
			jQuery('#special').click(function() {
				jQuery(this).fadeOut(500);						   
			});
	  }
	});
// end sequences


});  // the closing bracket to the document ready function

    //Carousel Tweaking
    function mycarousel_initCallback(carousel) {
        // Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });
    }

    ////////////////////////////////////////////////////////////////////////////
    // Set the big image corresponding to the thumbnail in the center position
    function mycarousel_itemLoadCallback(carousel) {
	// Get the middle thumbnail element
	// NOTE: This assumes there are 3 visible thumbnails
	middle_thumbnail_index = carousel.first + 1;
	middle_thumbnail_query = '"' + "li[jcarouselindex*='" + middle_thumbnail_index + "']" + '"'
	middle_thumbnail = jQuery(middle_thumbnail_query).children()[0];

	// Get the larger image corresponding to the middle thumbnail
	active_image_query = "." + middle_thumbnail.rel;
	active_image = jQuery(active_image_query);

	// Remove the current active image and set the new one from above
    jQuery('.active').removeClass('active');
	active_image.addClass('active');
    }
	
