function popUp(URL)
{
	
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 440,top = 125');");
	
}

$(function() {
		   
	$.swapImage(".swapImage");

});

Shadowbox.init({
	language: 'en',
	players:  ['img', 'html', 'iframe', 'qt', 'wmp', 'swf', 'flv']
});

var vCount = 0;

$(document).ready(function(){
	
	$.preloadCssImages();
	
	var newsScroll = $('#scroll-news').jScrollPane({
		showArrows: false,
		verticalDragMinHeight: 21,
		verticalDragMaxHeight: 21
	});
	
	
	$('#facebook-share-link').live('click',function(e) {
		
		e.preventDefault();
		
		window.open($(this).attr('href'),'newWindow','width=700,height=450');
		
	});
	
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
	{		
	
		$('#header-container').css('left', '0');
		$('#page-wrapper').css({'width':'1150px','margin-left':'auto','margin-right':'auto'});
		$('#content-container').css({'left':'50px'});
		$('#footer-container').css('width','1285px');
		$('#footer-container #blue-bar').css('width','1285px');
		$('.chart-titles').css('bottom','-10px');
		
	}
	
	//if ($('#scroll-news-content').length > 0)
		//$('#scroll-news-content').css('padding-bottom',($('.jspPane').height() - $('#scroll-news-content').height()) + 200);
		
	//alert($('.jspPane').height()+' - '+$('#scroll-news-content').height());
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').live('click',function(e) {
		
		e.preventDefault();
		
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().prepend('<a href="#" class="popup-close"><img src="//www.indygive.com/images/close-x.jpg" width="73" height="46" id="popup-close" class="btn_close swapImage {src: \'//www.indygive.com/images/close-xRO.jpg\'}" title="Close Window" alt="Close" /></a>');
		
		
		if ($('.scroll-pane').length > 0)
		{
			
			$('.scroll-pane').jScrollPane({
				showArrows: false,
				verticalDragMinHeight: 21,
				verticalDragMaxHeight: 21
			});
		
		}
		
		if ($('.tc-scroll-pane').length > 0)
		{
		
			$('.tc-scroll-pane').jScrollPane({
				showArrows: false,
				verticalDragMinHeight: 21,
				verticalDragMaxHeight: 21
			});
		
		}
		
		
		if ($('.pp-scroll-pane').length > 0)
		{
			
			$('.pp-scroll-pane').jScrollPane({
				showArrows: false,
				verticalDragMinHeight: 21,
				verticalDragMaxHeight: 21
			});
			
		}
		
		Cufon.refresh('.androgyne');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height()) / 2;
		var popMargLeft = ($('#' + popID).width()) / 2;
		/*
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : popMargTop,
			'margin-left' : -popMargLeft
		});
		*/
		
		$('html, body').animate({scrollTop:0}, 'slow');
		//Fade in Background
		$('body').append('<div id="page-fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#page-fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		//$.swapImage(".swapImage");
		
		return false;
	});
	
	
	//Close Popups and Fade Layer
	$('a.popup-close, img#popup-close, a#close').live('click', function() { //When clicking on the close or fade layer...
			
		var parent = $('a.popup-close').parent();
			
		if ($(parent).attr('page') == 'step-2')
		{
			
			window.location.href = '/';	
			
		}
																   
	  	$('#page-fade , .popup_block').fadeOut(function() {
			$('#page-fade, a.popup-close').remove();  
		}); //fade them both out
		
		return false;
	});

	$('div.audio-player').each(function() {
		
		var file = $(this).attr('file');
		
		$(this).html('<object type="application/x-shockwave-flash" data="/js/audio/player.swf" id="audioplayer'+vCount+'" height="26" width="225">\
						<param name="movie" value="/js/audio/player.swf">\
						<param name="FlashVars" value="playerID='+vCount+'&amp;bg=0xf8f8f8&amp;leftbg=0xeeeeee&amp;lefticon=0x666666&amp;rightbg=0xcccccc&amp;rightbghover=0x999999&amp;righticon=0x666666&amp;righticonhover=0xffffff&amp;text=0x666666&amp;slider=0x666666&amp;track=0xFFFFFF&amp;border=0x666666&amp;loader=0x9FFFB8&amp;loop=no&amp;autostart=no&amp;soundFile='+file+'">\
						<param name="quality" value="high">\
						<param name="menu" value="false">\
						<param name="wmode" value="transparent">\
					  </object>');
		
		vCount++;

	});
	

});



function showPopup(popID)
{

	//Fade in the Popup and add close button
	$('#' + popID).fadeIn().prepend('<a href="#" class="popup-close"><img src="//www.indygive.com/images/close-x.jpg" width="73" height="46" id="popup-close" class="btn_close swapImage {src: \'//www.indygive.com/images/close-xRO.jpg\'}" title="Close Window" alt="Close" /></a>');
	
	Cufon.refresh('.androgyne');
	
	$.swapImage(".swapImage");
	
	//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
	var popMargTop = ($('#' + popID).height() + 80) / 2;
	var popMargLeft = ($('#' + popID).width() + 80) / 2;
	/*
	//Apply Margin to Popup
	$('#' + popID).css({ 
		'margin-top' : popMargTop,
		'margin-left' : -popMargLeft
	});
	*/
		
	$('html, body').animate({scrollTop:0}, 'slow');
	//Fade in Background
	$('body').append('<div id="page-fade"></div>'); //Add the fade layer to bottom of the body tag.
	$('#page-fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
	
	return false;

}

function tellFriends()
{
		
	$('#tell-friends-loading').fadeIn();
	
	var popMargTop = ($('#tell-friends-loading').height() + 80) / 2;
	var popMargLeft = ($('#tell-friends-loading').width() + 80) / 2;
	/*
	$('#tell-friends-loading').css({ 
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	});
	*/
	
	$('html, body').animate({scrollTop:0}, 'slow');
	$('#tell-your-friends-content').append('<div id="tell-friends-fade"></div>');
	$('#tell-friends-fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
	
	var name = $('#t_name').val();	
	var email = $('#t_email').val();
	var friends = $('#t_friends').val();
	
	$.swapImage(".swapImage");	
	
	$.ajax({
		type: "POST",
		url: "/includes/process/eventHandler.php",
		data: 'action=send-to-friends&name='+name+'&email='+email+'&friends='+friends,
		success: function(data){
		   
			if(data == 0){
						
				// FAILED
				jAlert('There was an error.  Please try again.','Error');
			
			} else {
				
				// SUCCESS		
				closeLoading();	
				
				//$('a.popup-close').trigger('click');
				
				jAlert('Emails have been sent your friends.','Thank You!');
			
			}
	   },
		error : function(request, textStatus, errorThrown) {
			
			var process = '';
			
			switch (request.readyState)
			{
				
				case 1:
					process = 'loading';
					break;
				
				case 2:
					process = 'loaded';
					break;
				
				case 3:
					process = 'interactive';
					break;
				
				case 4:
					process = 'complete';
					break;
				
				
			}
			
			var status = '';
			
			switch (request.status)
			{
			
				case 400:
					status = 'Bad Request';
					break;
					
				case 401:
					status = 'Permission Error';
					break;
					
				case 403:
					status = 'Forbidden';
					break;
					
				case 404:
					status = 'Not Found';
					break;
					
				case 405:
					status = 'Action Forbidden';
					break;
					
				case 408:
					status = 'Time Out';
					break;
					
				case 500:
					status = 'Internal Error';
					break;
					
				default:
					status = 'Unspecified';
					break;
				
				
			}
			
			jAlert(' There was an error. Process - '+process+' Status - '+status,'Error');
		}
	 });
	
	return false;
	
}


function closeLoading()
{
															   
	$('#tell-friends-fade, #tell-friends-loading').fadeOut(function() {
		$('#tell-friends-fade').remove();  
	}); //fade them both out
	
}
	
