/*Accordion in the header*/

$(document).ready(function(){ 
$("#menu-menu-header").accordion({
			event: "mouseover"
		});
}); 

$(document).ready(function() 
{		
	$index = 1;
	$(document).cycle($index);
});

jQuery.fn.cycle = function($index)
{	
	$total = $('#rotateImage li').length;
	
	// hide rotating images and show current
	$('#rotateImage li').hide();
	$('#rotateImage li:nth-child('+$index+')').fadeIn('slow');
	
	// hilight current selection
	$('#rotateButtons li img').hide();
	$('#rotateButtons li:nth-child('+$index+') img:last').show();
	$('#rotateButtons li:lt('+($index-1)+') img:first-child').show();
	$('#rotateButtons li:gt('+($index-1)+') img:first-child').show();
	
	$index == $total ? $index = 1 : $index++;
	
	setTimeout('$(document).cycle('+$index+')', 3000);
}

/*Social Media popups*/
$( document ).ready(
	function( )
	{ 
		$( '#wod_social_facebook' ).bind( 	'click' , openFacebookPopup );
		$( '#wod_social_hyves' ).bind( 		'click' , openHyvesPopup );
		$( '#wod_social_twitter' ).bind( 	'click' , openTwitterPopup );
		$( '#wod_social_linkedin' ).bind( 	'click' , openLinkedinPopup );
	}
);

function openFacebookPopup( event )
{
	openWindow( $( this ).attr( 'href' ) , 600 , 400 );
	_gaq.push( [ '_trackPageview' , 'social_facebook' ] );
	event.preventDefault( );
}

function openHyvesPopup( event )
{
	openWindow( $( this ).attr( 'href' ) , 600 , 400 );
	_gaq.push( [ '_trackPageview' , 'social_hyves' ] );
	event.preventDefault( );
}

function openTwitterPopup( event )
{
	openWindow( $( this ).attr( 'href' ) , 600 , 400 );
	_gaq.push( [ '_trackPageview' , 'social_twitter' ] );
	event.preventDefault( );
}

function openLinkedinPopup( event )
{
	openWindow( $( this ).attr( 'href' ) , 600 , 400 );
	_gaq.push( [ '_trackPageview' , 'social_linkedin' ] );
	event.preventDefault( );
}

function openWindow( url , width , height )
{
	
	var winX = (document.all)?window.screenLeft:window.screenX;
	var winY = (document.all)?window.screenTop:window.screenY;

	wleft = winX + ( ($( window ).width( ) - width) / 2 );
	wtop = 200;
	handle	= window.open( url , 'socialmedia' , 'toolbar=no,location=no,menubar=no,scrollbars=yes,width=' + width + ',height=' + width + ',left=' + wleft + ', top=' + wtop + ',resizable=yes,status=no' );
}

