/*
 * Title: SJSU Rugby Website Common Javascript
 * Author: Rubeun S. Tan
 * Updated: October 12th, 2009
 *
 */

// init the $rugby namespace. All functions should be part of this namespace
var $rugby = window.$rugby || {};  

//
// createLink(): Given a jQuery selector and a URL, add an onclick event that 
// lets you click on a div to go to a new page 
//
$rugby.createLink = function(cssSelector, url) {
	$(cssSelector).click(function() { 
		if ($(this).hasClass('external')) {
			window.open( url );
        	return false;
		} else {
			location.href=url;
		}
	});
}


/**
 * initAnythingSlider(): setup the 'anything' slider, which is used on the homepage
 *
 */
$rugby.initAnythingSlider = function () {
	function formatText(index, panel) {
		  return index + "";
	}
	
	$(function () {
	
	    $('.anythingSlider').anythingSlider({
	        easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
	        autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
	        delay: 10000,                    // How long between slide transitions in AutoPlay mode
	        startStopped: false,            // If autoPlay is on, this can force it to start stopped
	        animationTime: 600,             // How long the slide transition takes
	        hashTags: true,                 // Should links change the hashtag in the URL?
	        buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             // Start text
	        stopText: "Stop",               // Stop text
	        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
	    });

	    
/*		Jump to slide 6
	    $("#slide-jump").click(function(){
	        $('.anythingSlider').anythingSlider(6);
	    });
*/
	    
	});
}



$rugby.initScrollable = function() {
    // initialize scrollable  
    $("div.scrollable").scrollable({ 
             
        // items are auto-scrolled in 2 secnod interval 
        interval: 2000, 
         
        // when last item is encountered go back to first item 
        loop: true,  
         
        // make animation a little slower than the default 
        speed: 600, 
         
        // when seek starts make items little transparent 
        onBeforeSeek: function() { 
            this.getItems().fadeTo(300, 0.2);         
        }, 
         
        // when seek ends resume items to full transparency 
        onSeek: function() { 
            this.getItems().fadeTo(300, 1); 
        } 
    });     

}


$(document).ready( function() {
   
    $('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

	// only init the sliders if they are found in the page
/*
	if ($('.anythingSlider').length > 0)
		$rugby.initAnythingSlider();
*/


	$('#coin-slider').coinslider({ width: 500, height: 500, navigation: false, delay: 8000 });		

	droplinemenu.buildmenu("droplinetabs1");    
        
    // insert a tooltip span that tells you that you're leaving the site
    // class='warning' can be applied to anything other than a link
    // class='warningLink' should only be applied to <a> tags, as it is needed to keep IE6 happy
    $('.warning, a.warningLink').append("<span>You are now exiting this web site.  SJSU Rugby is not responsible for the content or data collection of the website you are about to go to.</span>");
    $('.warning span').addClass('externalTooltip');	// only add externalTooltip class to the 'warning' objects (not the 'warningLink' objects)
    												// because IE6 has a hissy fit if the span inside the warningLink object has a class
});
