//------------------------------------------------------------------------------
// Javascript (jQuery) magic for custom LinkTrust theme for EWA Private Network
//
// (C)2010 PlasticBrain Media LLC | plasticbrain.net
//
//------------------------------------------------------------------------------
// Changlog
//------------------------------------------------------------------------------
//
//--- 2010-11-29 ---
//	Initial Version
//
//
//------------------------------------------------------------------------------

$(document).ready(function(){
	
	// Make flash movies opaque
	var isOpaque = 0;
	function makeFlashOpaque() {
		$('embed')
			.hide()
   		.attr('wmode', 'transparent')
   		.after('<param name="wmode" value="transparent" />')
   		.show();
   	isOpaque = true;
   	//console.log('flash should be opaque now...');
	}
	
	$('#slider').nivoSlider({
		pauseTime: 5000, 
		controlNav: false,
		directionNav: false
	});
	
	
	// Show popup message
	/*
	setTimeout(function(){
		var txt = 'We are working on integrating our new theme. While we are working on this, you may notice some strange happenings, incorrect figures, or other things. Please bear with us as we get all the kinks worked out!';
		$.prompt(txt,{buttons:{Ok:true}}); 
	}, 3000);
	*/
	
	function impromptuCallback(v,m,f) {
		//alert(v + ', ' + m + ', ' + f);
		//$('embed').show();
	}
	
	jQuery.prompt.setDefaults({
		prefix: 'cleanBlue',
		show: 'slideDown',
		callback: impromptuCallback
	});
	
	$('a.showImage').fancybox({
		'overlayShow' : true,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'easingIn' : 'easeOutBack',
		'speedOut' : 500,
		'speedIn' : 1000,
		'easingOut' : 'easeInBack',
		'showCloseButton' : true,
		'onClosed'	: function() {
			if( isOpaque === 1 ) {
				$('embed').show();	
   			isOpaque = true;
   			//console.log('flash should be opaque now...');
			}
			//setTimeout(function(){$('embed').show();}, 3000);
		},
		onStart :	function() {
			if( isOpaque == false ) {
				$('embed').hide()
					.attr('wmode', 'transparent')
   				.after('<param name="wmode" value="transparent" />')
   			isOpaque = 1;
			}
			//setTimeout(function(){$('embed').hide();}, 3000);
		}
	}).mouseenter(function(){
	}).mouseleave(function(){
	});
	
	$('a.game').click(function(){
		$.fancybox({
			'width'	: '75%',
			'height' : '75%',
			'autoScale' : false,
			'overlayShow' : true,
			'transitionIn' : 'fade',
			'transitionOut' : 'fade',
			'showCloseButton' : true,
			'href' : this.href,
			'type' : 'iframe',
			'onClosed' : function() {
				if( isOpaque === 1 ) {
					$('embed').show();	
   				isOpaque = true;
   				//console.log('flash should be opaque now...');
				}
			},
			'onStart' : function() {
				if( isOpaque == false ) {
					$('embed').hide()
						.attr('wmode', 'transparent')
   					.after('<param name="wmode" value="transparent" />')
   					isOpaque = 1;
				}
			}
		})
		return false;
	});
	
	$('.games').fancybox({
		'width'	: '600px',
		'height' : '275px',
		'autoScale' : true,
		'overlayShow' : true,
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'easingIn' : 'easeOutBack',
		'speedOut' : 500,
		'speedIn' : 1000,
		'easingOut' : 'easeInBack',
		'showCloseButton' : true,
		'onClosed' : function() {
			if( isOpaque === 1 ) {
				$('embed').show();	
   			isOpaque = true;
   			//console.log('flash should be opaque now...');
			}
		},
		'onStart' : function() {
			if( isOpaque == false ) {
				$('embed').hide()
					.attr('wmode', 'transparent')
   				.after('<param name="wmode" value="transparent" />')
   				isOpaque = 1;
			}
		}
	});
	
	
	$('a.cGuides').click(function(){
		$.fancybox({
			'width'	: '75%',
			'height' : '75%',
			'autoScale' : false,
			//'title' : 'Weekly Campaign Guides',
			//'titlePosition' : 'over',
			'overlayShow' : true,
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic',
			'easingIn' : 'easeOutBack',
			'speedOut' : 500,
			'speedIn' : 1000,
			'easingOut' : 'easeInBack',
			'showCloseButton' : true,
			'href' : this.href,
			'type' : 'iframe',
			'onClosed' : function() {
				if( isOpaque === 1 ) {
					$('embed').show();	
   				isOpaque = true;
   				//console.log('flash should be opaque now...');
				}
			},
			'onStart' : function() {
				if( isOpaque == false ) {
					$('embed').hide()
						.attr('wmode', 'transparent')
   					.after('<param name="wmode" value="transparent" />')
   					isOpaque = 1;
				}
			}
		})
		return false;
	});


	// Highlight the "current" page in the menu
	function highlightPage() { 
		var page = window.location.pathname;
		//console.log(page);
		
		if( page == '/Home.aspx' ) {
			$('a#home').addClass('current');	
			
		} else if( page == '/MyOffers.aspx' ) {
			$('a#my_offers').addClass('current');
			
		} else if( page == '/RequestOffers.aspx' || page == '/OfferDetails.aspx' ) {
			$('a#request_offers').addClass('current')
			;					
		} else if( page == '/Reporting.aspx' || page == '/RptCampaignPerformance.aspx' ) {
			$('a#reporting').addClass('current');			
		}
		
	}
	
	highlightPage();

	//------------------------------------------------------------------------------
	// Toggle Modules
	//------------------------------------------------------------------------------
	$('.module.collapsible h3').click(function(){
		var el = $(this);
		if( el.hasClass('collapsed') ) {
			el.attr('title', 'Minimize Section')
				.removeClass('collapsed')
				.parents('.module')
				.find('.mContent')
				.slideDown(500);
		} else {
			el.attr('title', 'Expand Section')
				.addClass('collapsed')
				.parents('.module')
				.find('.mContent').
				slideUp(500);
		}
		return false;
	});
	$('.module.collapsible h3').attr('title', 'Minimize Section');

	//------------------------------------------------------------------------------
	// Stripe Tables
	//------------------------------------------------------------------------------
	function stripeTables() {
		$('table tr').removeClass('even').removeClass('odd');
		$('table tr:even').addClass('even');
		$('table tr:odd').addClass('odd');
	}

	//------------------------------------------------------------------------------
	// Hover action on table rows
	//------------------------------------------------------------------------------
	$('table tr').live('mouseenter', function(){
		$(this).addClass('hover');
	});
	$('table tr').live('mouseleave', function(){
		$(this).removeClass('hover');
	});
	
	//------------------------------------------------------------------------------
	// Auto focus fields
	//------------------------------------------------------------------------------
	$('.focus').focus();
	
	$('.nyi').click(function(){
		alert("This feature is not yet implemented.");
		return false;
	});

	//------------------------------------------------------------------------------
	// Fade elements IN on mouseover
	//------------------------------------------------------------------------------
	$('.fadeInOnHover').mouseenter(function(){
		$(this).stop(true, true).animate({opacity: 1}, 300);
	}).mouseleave(function() {
		$(this).stop(true, true).animate({opacity: .5}, 700);
	});

	$('.fadeInOnHover').css({opacity: .5});
	//------------------------------------------------------------------------------
	// Fade elements OUT on mouseover
	//------------------------------------------------------------------------------
	$('.fadeOutOnHover').mouseenter(function(){
		$(this).stop(true, true).animate({opacity: .5}, 300);
	}).mouseleave(function() {
		$(this).stop(true, true).animate({opacity: 1}, 700);
	});

	$('.hide').hide();
	$('.show').show();
	
	setTimeout(function(){
		$('.fadeIn').fadeIn(300);
	}, 2000);

});
