/*
 * 
 * bigadgig.js
 * 
 * provides encapsulation for the bigadgig html and data
 *
 */

window.Atmosphere = {};

Atmosphere.BigAdGig = function(stage){
	
	if(typeof( stage ) == "undefined"){ stage = 'signin'; }
	if(typeof( previous_stage ) == "undefined"){ previous_stage = ''; }
	if(typeof( name ) == "undefined"){ name = ''; }
	if(typeof( fname ) == "undefined"){ fname = ''; }
	if(typeof( lname ) == "undefined"){ lname = ''; }
	if(typeof( fb_uid ) == "undefined"){ fb_uid = ''; }
	if(typeof( yt_vid ) == "undefined"){ yt_vid = ''; }
	if(typeof( email ) == "undefined"){ email = ''; }
	if(typeof( file_extension ) == "undefined"){ file_extension = ''; }
	if(typeof( html ) == "undefind"){ html = ''; }
	if(typeof( hasPerm ) == "undefind"){ hasPerm = false; }
	if(typeof( allowed_file_types ) == "undefined"){ 
		allowed_file_types = []; 
		allowed_file_types[0] = 'pdf';
		allowed_file_types[1] = 'rtf';
		allowed_file_types[2] = 'txt';	
	}

	this.stage = stage,
	this.previous_stage = previous_stage,
	this.setStage = function(value){
		this.previous_stage = this.stage;
		this.stage = value;
	},
	this.name = name,
	this.fname = fname,
	this.lname = lname,
	this.email = email,
	this.fb_uid = fb_uid,
	this.yt_vid = yt_vid,
	this.file_extension = file_extension,
	this.allowed_file_types = allowed_file_types,
	this.html = '',
	this.hasPerm,
	this.getFBPerm = function(){
		if( this.hasPerm == "undefined" )
			this.hasPerm = false;
		return this.hasPerm;
	},
	this.file_type_is_valid = function( ext )
	{
		if(this.file_extension = '')
			this.file_extension = ext;
		
		for(var i=0; i<allowed_file_types.length; i++)
		{
			if( allowed_file_types[i] == this.file_extension )
				return true;	
		}
		return false;
	},
	this.getHtml = function()
	{
		switch( this.stage )
		{
			case 'signin':
				var directionalCopy =	"If this is your first time registering for The Big Ad Gig 2010, enter "+
										"your Facebook login to get started.<br /><br />"+
										"If you've already registered, just reenter your Facebook login to pick "+
										"up where you left off. Don't have a Facebook account? "+
										"<a class='text-link' href='http://www.facebook.com/'>Create one here</a>, then come back.<br /><br />"+
										"Please note: all correspondence from The Big Ad Gig will be sent to the email "+
										"address linked to your Facebook account, so make sure to check it frequently.";
					
				this.html =	'<table border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/enter/header_sign.gif" alt="Enter your Facebook login." />' +
									'</td>' +	
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p class="section-text narrow" id="directionRow">'+ directionalCopy +'</p>' + 
									'</td>' +
									'<td>' +
										'<div id="signin-dash-line">' +
											'<img src="images/details/dashed_line_decoration_5.gif" />' +
										'</div>' +
									'</td>' +
								'</tr>' +
							'</table>';
				
				break;
				
			case 'signup':
				
				var directionalCopy =	"We've got your name and email, thanks internet. Now, complete your "+
										"entry form by uploading links to your portfolio and resume, then get"+
										"started on your YouTube video.<br /><br />"+
										"Remember your video, resume and portfolio must be submitted before "+
										"the entry deadline on August 23rd.";
				
				var tempHtml = '';						
				tempHtml +=	'<table border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr>'+
									'<td>'+
										'<img class="page-title" src="images/enter/header_portfolio.gif" alt="Now enter the rest of your info." />'+
									'</td>'+	
								'</tr>'+				
								'<tr>' +
									'<td>' +
										'<p class="section-text narrow" id="directionRow">'+ directionalCopy +'</p>' + 
									'</td>' +
								'<tr>'+
									'<td>'+
										'<form class="cmxform" id="form1" method="post" action="php/upload.php"  enctype="multipart/form-data" target="upload_target">' +
											'<label for="email" style="margin-top:40px;">Your email address:</label>' +
											'<p class="section-text">' +
												'<span id="email">'+ this.email +'</span>' +
											'</p>' +
											'<label for="fname" style="margin-top:20px;">Your first name:</label>' +
											'<p class="section-text">' +
												'<span id="fname">'+ this.fname +'</span>' +
											'</p>' +
											'<label for="lname" style="margin-top:20px;">Your last name:</label>' +
											'<p class="section-text">' +
												'<span id="lname">'+ this.lname +'</span>' +
											'</p>' +
											'<label for="portfolio" style="margin-top:20px;">Your portfolio URL:</label>' +
											'<p class="section-text">' +
												'<input type="text" id="portfolio" name="portfolio" size="30" class="required url" />' +
											'</p>' +
											'<label for="resume" style="margin-top:20px;">Upload your resume: (under 2MB)</label>' +
											'<p class="section-text">' +
												'<input type="file" id="resume" name="resume" size="30" class="required" accept="pdf|rtf|txt" />' +
											'</p>' +
											'<p class="label_checkbox">' +
												'<input type="checkbox" id="agree" name="agree" />' +
												'<label id="agree-label" for="agree">I agree to the <a class="text-link" href="terms.phtml" target="_blank">Terms &amp; Conditions</a></label>' +
											'</p>' +
											'<p id="agree-error" class="error">You must agree to the Terms and Conditions.</p>'; 
											
							tempHtml +=		'<p class="submit-holder" style="margin-top:40px;">' +
												'<input class="rollover_gradient" type="image" src="images/global/cta_submit.gif" value="Submit" />' +
												'<span id="status-loader">' +
													'<img src="images/circle_loader.gif" />' +
												'</span>' +
											'</p>' +
										'</form>' +
										'<iframe id="upload_target" name="upload_target" src="#"></iframe>' +
										'<div id="response"></div>' +
									'</td>' +
								'</tr>' +
							'</table>';
				
				this.html = tempHtml;
				break;
				
			case 'video_update':
				
				var directionalCopy = 	"Shot your video? Uploaded it to your YouTube account? Just paste in the "+
										"YouTube URL below. Still procrastinating? Make sure you do it before the "+
										"entry deadline on August 23rd.";
										
				var tempHtml = '';					
				tempHtml +=	'<table border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr>'+
									'<td>'+
										'<img class="page-title" src="images/declare/header_upload.gif" alt="Now enter the link to your YouTube video." />'+
									'</td>'+	
								'</tr>'+				
								'<tr>' +
									'<td>' +
										'<p class="section-text narrow" id="directionRow">'+ directionalCopy +'</p>' + 
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<form class="cmxform" id="form1" method="post" action="">' +
											'<label for="email" style="margin-top:40px;">Your email address:</label>' +
											'<p class="section-text">' +
												'<span id="email">'+ this.email +'</span>' +
											'</p>' +
											'<label for="fname" style="margin-top:20px;">Your first name:</label>' +
											'<p class="section-text">' +
												'<span id="fname">'+ this.fname +'</span>' +
											'</p>' +
											'<label for="lname" style="margin-top:20px;">Your last name:</label>' +
											'<p class="section-text">' +
												'<span id="lname">'+ this.lname +'</span>' +
											'</p>' +
											'<label for="video" style="margin-top:20px;">Your YouTube URL:</label>' +
											'<p>' +
												'<input style="font-size:15px;" type="text" id="video" name="video" size="30" class="required url" />' +
											'</p>';
							tempHtml +=		'<input type="hidden" id="token" name="token"/>';
							tempHtml +=		'<p class="submit-holder" style="margin-top:40px;">' +
												'<input class="rollover_gradient" type="image" src="images/global/cta_submit.gif" value="Submit"/>' +
												'<span id="status-loader">' +
													'<img src="images/circle_loader.gif" />' +
												'</span>' +
											'</p>' +
										'</form>' +
									'</td>' +
								'</tr>' +
							'</table>';										
				
				this.html = tempHtml;
				break;
			
			case 'all_done':
			
				var directionalCopy = 	"We'll notify you via the email linked to your Facebook account once " +
										"your video has been approved. When you get the good word, make sure " +
										"to share your video with as many friends as possible. The video with " +
										"the most votes gets an automatic bid to The Big Ad Gig finals. " +
										"The voting polls will close on August 31st at 11:59 PM.";
										
				this.html =	'<table border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr>'+
									'<td>'+
										'<img class="page-title" src="images/enter/header_confirm.gif" alt="Thanks for completing your submission." />'+
									'</td>'+	
								'</tr>'+
								'<tr>' +
									'<td>' +
										'<p class="section-text narrow" id="directionRow">'+ directionalCopy +'</p>' + 
									'</td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p class="submit-holder" style="margin-top:40px;">' +
											'<a href="judges.phtml">' +
												'<img id="meet-judges" src="images/global/cta_meet_judges.gif" />' +
											'</a>' +
										'</p>' +
									'</td>' +
								'</tr>' +
							'</table>';
				break;
			
			case 'accepted':
				
				var directionalCopy =	"Congrats &mdash; your video has been approved by our judges, now it's time "+
										"to get the word out.<br /><br />"+
										"Make sure to &quot;like&quot; your video on the "+
										"<a class='text-link' href='http://www.thebigadgig.com/vote.phtml?vid="+ this.yt_vid +"'>Vote</a> " +
										"page and share it with as many people as possible. The video with the most votes will get its "+
										"creator an automatic bid to The Big Ad Gig finals. The voting polls will close on August 31st at 11:59 PM.";
										
				this.html =	'<table border="0" cellspacing="0" cellpadding="0" summary="">' +
								'<tr height="100px">' +
									'<td colspan="1" align="left" style="vertical-align:bottom;">' +
										'<img class="page-title" src="images/enter/header_back.gif" alt="Thanks for completing your submission." />' +
									'</td>' +	
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<p class="section-text narrow" id="directionRow">'+ directionalCopy +'</p>' + 
										'<p class="submit-holder" style="margin-top:40px;">' +
											'<a href="judges.phtml">' +
												'<img id="meet-judges" src="images/global/cta_meet_judges.gif" />' +
											'</a>' +
										'</p>' +
									'</td>' +
									'<td>' +
										'<div id="accept-dash-line">' +
											'<img src="images/details/dashed_line_decoration_5.gif" />' +
										'</div>' +
									'</td>' +									
								'</tr>' +
							'</table>';
				break;				
				
		}
		return this.html
	},
	this.applyEventHandlers = function( page, include_top_nav )
	{	
	
		var link_privacy = $('.privacy-link').bind('click', function(e){
				e.preventDefault();
				window.open('privacy.html','Privacy_Policy', 'width=600,height=600,left=0,top=0,menubar=no,status=no,location=no,toolbar=no,scrollbars=no');
			});
	
		switch( page )
		{
			case 'home':
				
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get_over.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get.gif'); });
		
				var nav_enter = $('#top-nav-enter')
					.mouseover( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter_over.gif'); })
					.mouseout( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter.gif'); });

				var nav_vote = $('#top-nav-vote')
					.mouseover( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote_over.gif'); })
					.mouseout( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote.gif'); });

				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				var nav_sponsors = $('#top-nav-sponsors')
					.mouseover( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see_over.gif'); })
					.mouseout( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see.gif'); });

				break;
			
			case 'details':
				
				$('#top-nav-details').find('img').attr('src', 'images/header/header_bar_get_over.gif');
		
				var nav_enter = $('#top-nav-enter')
					.mouseover( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter_over.gif'); })
					.mouseout( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter.gif'); });

				var nav_vote = $('#top-nav-vote')
					.mouseover( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote_over.gif'); })
					.mouseout( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote.gif'); });

				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				var nav_sponsors = $('#top-nav-sponsors')
					.mouseover( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see_over.gif'); })
					.mouseout( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see.gif'); });

				var button_enter_top = $('#button-enter-top')
					.mouseover( function(e) { button_enter_top.find('img').attr('src', 'images/global/cta_enter_now_over.gif'); })
					.mouseout( function(e) { button_enter_top.find('img').attr('src', 'images/global/cta_enter_now.gif'); })

				var button_enter_bottom = $('#button-enter-bottom')
					.mouseover( function(e) { button_enter_bottom.find('img').attr('src', 'images/global/cta_enter_now_over.gif'); })
					.mouseout( function(e) { button_enter_bottom.find('img').attr('src', 'images/global/cta_enter_now.gif'); })
									
				
				break;

			case 'enter':

				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get_over.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get.gif'); });
		
				$('#top-nav-enter').find('img').attr('src', 'images/header/header_bar_enter_over.gif');

				var nav_vote = $('#top-nav-vote')
					.mouseover( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote_over.gif'); })
					.mouseout( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote.gif'); });

				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				var nav_sponsors = $('#top-nav-sponsors')
					.mouseover( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see_over.gif'); })
					.mouseout( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see.gif'); });

				var submit_holder = $('.rollover_gradient')
					.mouseover( function(e) { submit_holder.attr('src', 'images/global/cta_submit_over.gif'); })
					.mouseout( function(e) { submit_holder.attr('src', 'images/global/cta_submit.gif'); });

				var meet_judges = $('#meet-judges')
					.mouseover( function(e) { meet_judges.attr('src', 'images/global/cta_meet_judges_over.gif'); })
					.mouseout( function(e) { meet_judges.attr('src', 'images/global/cta_meet_judges.gif'); });
				break;
				
			case 'vote':
				
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get_over.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get.gif'); });
		
				var nav_enter = $('#top-nav-enter')
					.mouseover( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter_over.gif'); })
					.mouseout( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter.gif'); });

				$('#top-nav-vote').find('img').attr('src', 'images/header/header_bar_vote_over.gif');

				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				var nav_sponsors = $('#top-nav-sponsors')
					.mouseover( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see_over.gif'); })
					.mouseout( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see.gif'); });

				break;
			
			case 'judges':
				
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get_over.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get.gif'); });
		
				var nav_enter = $('#top-nav-enter')
					.mouseover( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter_over.gif'); })
					.mouseout( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter.gif'); });

				var nav_vote = $('#top-nav-vote')
					.mouseover( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote_over.gif'); })
					.mouseout( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote.gif'); });

				$('#top-nav-judges').find('img').attr('src', 'images/header/header_bar_meet_over.gif');
				//var nav_judges = $('#top-nav-judges')
				//	.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
				//	.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				var nav_sponsors = $('#top-nav-sponsors')
					.mouseover( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see_over.gif'); })
					.mouseout( function(e) { nav_sponsors.find('img').attr('src', 'images/header/header_bar_see.gif'); });

				break;
			
			case 'partners':
				
				var nav_details = $('#top-nav-details')
					.mouseover( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get_over.gif'); })
					.mouseout( function(e) { nav_details.find('img').attr('src', 'images/header/header_bar_get.gif'); });
		
				var nav_enter = $('#top-nav-enter')
					.mouseover( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter_over.gif'); })
					.mouseout( function(e) { nav_enter.find('img').attr('src', 'images/header/header_bar_enter.gif'); });

				var nav_vote = $('#top-nav-vote')
					.mouseover( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote_over.gif'); })
					.mouseout( function(e) { nav_vote.find('img').attr('src', 'images/header/header_bar_vote.gif'); });

				var nav_judges = $('#top-nav-judges')
					.mouseover( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet_over.gif'); })
					.mouseout( function(e) { nav_judges.find('img').attr('src', 'images/header/header_bar_meet.gif'); });
					
				$('#top-nav-sponsors').find('img').attr('src', 'images/header/header_bar_see_over.gif');

				break;

			default:
				break;
		}
	}
}
