jQuery(function(){

	jQuery('a.external').click(function(){
		trackLink( this.href , this); // Fire an Omniture click event
		window.open(this.href);
		//setTimeout(function(){window.open(theLinkURL)},500);
		return false;
	});

	jQuery(function(){

		jQuery("sup").each(function (i) {
			var parent = jQuery(this).parent().get(0);
			if(parent.firstChild==jQuery(this).get(0)){
				jQuery(parent).addClass("small");
			}
		  });
	});
	
	// jQuery("div.scrollable").scrollable();
	
	// initialize scrollable 
//	jQuery("div.scrollable").scrollable({
//		circular:'true'
//	}).navigator({
//		navi:'ul.scrollable-navi',
//		naviItem:'a'
//	});
	
//	jQuery(".video-scrollable a.youtube-video").click(function() {
//		var videoId = $(this).id;		 
//		yt_player.loadVideoById(videoId, 0, 'medium');
//		return false;
//	});
	
});

//function onYouTubePlayerReady(playerId) {
//	yt_player = document.getElementById(playerId);
//	yt_player.cueVideoById(firstVideo, 0, 'medium');
//}


var Spotlight = {
	'Facebook':'ad.doubleclick.net/activity;src=1139843;type=pgenz722;cat=onsta793',
	'Youtube':'ad.doubleclick.net/activity;src=1139843;type=pgenz722;cat=onsta497',
	'Twitter':'ad.doubleclick.net/activity;src=1139843;type=pgenz722;cat=onsta741',
	'RSS Feed':'ad.doubleclick.net/activity;src=1139843;type=pgenz722;cat=onsta621',
	'setupform':'fls.doubleclick.net/activityi;src=1139843;type=pstar455;cat=onsta712',
	'contactform':'ad.doubleclick.net/activity;src=1139843;type=eeclx810;cat=onsta835'
};

/*	================================
Create Sidebar Promo Rotator
Depends on JQuery Cycle plugin
================================*/
function makePromoRotator() {

	// Set slideshow variables
	jQuery('div#promo_rotator').after('<div id="promonav"><div id="promonav_container"><a id="prev" href="#" title="Previous">Prev</a><div id="promonav_inner"></div><a id="next" href="#" title="Next">Next</a></div></div>').cycle({
		fx: 'turnLeft',
		speed: 800,
		timeout: 10000,
		pause: 1,
		next: '#next', 
		prev: '#prev',
		pager: '#promonav_inner'
	});

	//Track clicks to the promo slider
	jQuery('div#promo_rotator a').click(function(e){
		var promoLinkName = 'ONSTAR CONNECTIONS | PROMO SLIDER | ';
		var promoLinkTitle = e.target['title']; // Get the image title
		promoLinkName = promoLinkName.concat(promoLinkTitle); // Add image title to the link name
		trackLink( promoLinkName , this); // Fire an Omniture click event
	})
}




jQuery(document).ready(function() {

	// Functions to be performed at load

	jQuery("[class*=spotlight]").click(function() {
		var elem=jQuery(this)[0];
		var spotlightName = elem.title;
		if(elem.tagName.toLowerCase()=='input'){
			spotlightName=elem.form.id;
		}
		if(spotlightName!="" && Spotlight[spotlightName]){
			var axel = Math.random()+"";
			var a = axel * 10000000000000;
			var spotlightTag = new Image();
			spotlightTag.src = "http://" + Spotlight[spotlightName] + ";ord=" + a + "?";
		}

	});

	// Slide down categories panel when "stories" is clicked

	var storiesButton = jQuery('ul#nav li a.stories');
	storiesButton.click(function(){
		var arrow = jQuery(this).find('img');
		jQuery('div#stories_drop').slideToggle(500);
		if(arrow.attr('src') == '/wp-content/themes/onstar_connect_v2/images/gui/icon/down_arrow.png'){
			arrow.attr('src', '/wp-content/themes/onstar_connect_v2/images/gui/icon/up_arrow.png')
		}else{
			arrow.attr('src', '/wp-content/themes/onstar_connect_v2/images/gui/icon/down_arrow.png')
		}
		return false;
	})

	// Create the multi-pane stories sidebar widget

		// Get all variables
		var topicsPane = jQuery('ul#topic');
		var recentPane = jQuery('ul#recent');
		var archivePane = jQuery('ul#archive');

		// Set positioning and add event listener
		jQuery("div#stories_widget h3").css({"position":"absolute", "top":"0px"}).click(function(){
			topicsPane.hide();
			recentPane.hide();
			archivePane.hide();
			jQuery("div#stories_widget h3").removeClass('current');
			jQuery(this).addClass('current').next('ul').show();
			return false;
		});

		// Set individual link positions
		jQuery('h3#topics_pane').css("left","100px");
		jQuery('h3#recent_pane').css("left","170px");
		jQuery('h3#archives_pane').css("left","240px");

		// Hide
		recentPane.hide();
		archivePane.hide();

	// Create Top slide-down panel
	jQuery('a#tab').click(function(){
		var arrow = jQuery(this).find('img');
		var panel = jQuery('div#slider_panel');
		if(panel.hasClass('open')){
			// We're closing the tab
			panel.removeClass('open');
		}else{
			// We're opening the tab
			panel.addClass('open');
			// Fire an Omniture event
			trackLink('ONSTAR CONNECTIONS | HEADER | MANAGE YOUR ACCOUNT', this)
		}
		jQuery('#account_panel').slideToggle(500);
		if(arrow.attr('src') == '/wp-content/themes/onstar_connect_v2/images/gui/icon/down_arrow.png'){
			arrow.attr('src', '/wp-content/themes/onstar_connect_v2/images/gui/icon/up_arrow.png')
		}else{
			arrow.attr('src', '/wp-content/themes/onstar_connect_v2/images/gui/icon/down_arrow.png')
		}
		return false;
	})

	makePromoRotator();


});


