 $(document).ready(function(){
 
	 function pages(page) {
	    var pages = page.split('/');
	    if (pages[1]) {
		    page = pages[0];
		    var subpage = pages[1];	    
	    }
		var target = $('#'+page);
		if (page=='trailer') {
		    $('#contentWrapper').animateToClass('trailer',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    	$('#trailerCover').show().delay(1000).fadeOut();
		    });
		    $('#videoTrailer').live('click',function(){
		    	$('#trailerCover').show().delay(1000).fadeOut();
		    	$('#videoWrapper').html('<iframe width="560" height="349" src="http://www.youtube.com/embed/nAbL80Z3DrA" frameborder="0" allowfullscreen></iframe>');
		    	return false;
		    });
		    $('#videoTrailer2').live('click',function(){
		    	$('#trailerCover').show().delay(1000).fadeOut();
		    	$('#videoWrapper').html('<iframe width="560" height="349" src="http://www.youtube.com/embed/87ZbDrKI5YA" frameborder="0" allowfullscreen></iframe>');
		    	return false;
		    });
		    $('#videoMauicruiser').live('click',function(){
		    	$('#trailerCover').show().delay(1000).fadeOut();
		    	$('#videoWrapper').html('<iframe width="560" height="349" src="http://www.youtube.com/embed/hAi6nSVzliU" frameborder="0" allowfullscreen></iframe>');
		    	return false;
		    });
		    $('#videoInterview').live('click',function(){
		    	$('#trailerCover').show().delay(1000).fadeOut();
		    	$('#videoWrapper').html('<iframe width="560" height="349" src="http://www.youtube.com/embed/jjiQpteEhaY" frameborder="0" allowfullscreen></iframe>');
		    	return false;
		    });
		} else if (page=='about') {
			$('.menuItem a[rel=about]').click(function(){
				$('#aboutFrame').html('<div style="text-align:center;"><img src="/images/About-Synopsis.jpg" width="793" height="397" /></div>');
			}).click();
		    $('#contentWrapper').animateToClass('about',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
		    $('.aboutMenuItemInner a').click(function(){
		    	$('.aboutMenuItemInner a.active').removeClass('active');
		    	$('#aboutLinks a.activee').removeClass('activee');
		    	$(this).addClass('active');		    
		    });
		    $('#synopsisLink').click(function(){
		    	$('.aboutMenuItemInner a.active').removeClass('active');
		    	$('#aboutLinks a.activee').removeClass('activee');
		    	$(this).addClass('activee');
				$('#aboutFrame').html('<img src="/images/About-Synopsis.jpg" width="793" height="397" />');
		    });
		    $('#productionNotesLink').click(function(){
		    	$('.aboutMenuItemInner a.active').removeClass('active');
		    	$('#aboutLinks a.activee').removeClass('activee');
		    	$(this).addClass('activee');
				$('#aboutFrame').html('<img src="/images/About-Production-Notes.jpg" width="793" height="397" />');
		    });
		    $('#brianKohne').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/149?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#stefanSchaefer').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/150?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#willieK').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/151?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#ericGilliom').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/152?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#carolynOmine').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/153?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#jakeShimabukuro').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/154?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#augieT').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/155?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#castcrew').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/157?framed=yes" width="800" height="400"></iframe>');
		    });
		    $('#barefootNatives').click(function(){
		    	$('#aboutFrame').html('<iframe src="/node/156?framed=yes" width="800" height="400"></iframe>');
		    });
		} else if (page=='reviews') {
			if ($('#'+page+' iframe').length==0) {
				target.html('<iframe src="http://getajobmovie.com/reviews?framed=yes" width="680" height="330" scrolling="no" frameborder="no"></iframe>').fadeIn().addClass('curpage');
			}
		    $('#contentWrapper').animateToClass('reviews',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
	/*	    $.ajax({
		    	type: 'GET',
		    	url: 'http://getajobmovie.com/reviews',
		    	data: 'callback=yes',
		    	cache: 'false',
		    	success: function(data) {
		    		$('#loading').fadeOut();
		    		target.html(data).fadeIn().addClass('curpage');				
		    	}
		    });*/
		} else if (page=='photos') {
		    if (subpage) {
		        if (subpage=='horizontal') {
		          var horizontal = ' class="active"';
		        } else if (subpage=='vertical') {
		          var vertical = ' class="active"';
		        } else if (subpage=='artwork') {
		          var artwork = ' class="active"';
		        }
				target.html('<div id="photosLinks" style="position:absolute;top:30px;right:25px;"><h3 style="float:left;"><a href="#/photos/horizontal" rel="horizontal"'+horizontal+'>Horizontal</a></h3><h3 style="float:left;"> &nbsp; | &nbsp; </h3><h3 style="float:left;"><a href="#/photos/vertical" rel="vertical"'+vertical+'>Vertical</a></h3><h3 style="float:left;"> &nbsp; | &nbsp; </h3><h3 style="float:left;"><a href="#/photos/artwork" rel="artwork"'+artwork+'>Artwork</a></h3></div><iframe src="http://getajobmovie.com/press/photos/'+subpage+'?framed=yes" width="720" height="420" frameborder="no"></iframe>');		      
		    } else if ($('#'+page+' iframe').length==0) {
				target.html('<div id="photosLinks" style="position:absolute;top:30px;right:25px;"><h3 style="float:left;"><a href="#/photos/horizontal" rel="horizontal" class="active">Horizontal</a></h3><h3 style="float:left;"> &nbsp; | &nbsp; </h3><h3 style="float:left;"><a href="#/photos/vertical" rel="vertical">Vertical</a></h3><h3 style="float:left;"> &nbsp; | &nbsp; </h3><h3 style="float:left;"><a href="#/photos/artwork" rel="artwork">Artwork</a></h3></div><iframe src="http://getajobmovie.com/press/photos/horizontal?framed=yes" width="720" height="420" frameborder="no"></iframe>');
			}
		    $('#contentWrapper').animateToClass('photos',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
		    $('#photosLinks a').click(function(){
		    	var rel = $(this).attr('rel');
		    	location.hash = '/photos/'+rel;
		    	$('#photosLinks a.active').removeClass('active');
		    	$(this).addClass('active');
		    	$('#photos iframe').remove();
		    	$('#photosLinks').after('<iframe src="http://getajobmovie.com/press/photos/'+rel+'?framed=yes" width="720" height="420" frameborder="no"></iframe>');
		    });
		} else if (page=='buy') {
		    $('#contentWrapper').animateToClass('buy',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
		} else if (page=='screenings') {
			if ($('#'+page+' iframe').length==0) {
				target.html('<iframe src="http://getajobmovie.com/screenings?framed=yes" width="900" height="420" frameborder="no"></iframe>');
				//target.html('<iframe src="http://getajobmovie.com/tickets?framed=yes" width="900" height="420" frameborder="no"></iframe>');
			}
		    $('#contentWrapper').animateToClass('screenings',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
	/*	    $.ajax({
		    	type: 'GET',
		    	url: 'http://getajobmovie.com/tickets',
		    	data: 'framed=yes',
		    	cache: 'false',
		    	success: function(data) {
		    		$('#loading').fadeOut();
		    		target.html(data).fadeIn().addClass('curpage');				
		    	}
		    });*/
		} else if (page=='poster') {
		    $('#contentWrapper').animateToClass('poster',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<img src="/new/GetAJobPoster.jpg" width="715" />').fadeIn().addClass('curpage');
		    });
		} else if (page=='poster2') {
		    $('#contentWrapper').animateToClass('poster2',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<img src="/new/poster-2.jpg" width="715" />').fadeIn().addClass('curpage');
		    });
		} else if (page=='poster3') {
		    $('#contentWrapper').animateToClass('poster3',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<img src="/new/poster-3.jpg" width="715" />').fadeIn().addClass('curpage');
		    });
		} else if (page=='poster4') {
		    $('#contentWrapper').animateToClass('poster4',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<img src="/new/poster-4.jpg" width="715" />').fadeIn().addClass('curpage');
		    });
		} else if (page=='poster5') {
		    $('#contentWrapper').animateToClass('poster5',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<img src="/new/poster-5.jpg" width="715" />').fadeIn().addClass('curpage');
		    });
		} else if (page=='newsletter') {
		    $('#contentWrapper').animateToClass('newsletter',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<div style="width:640px;height:340px;background:url(\'/images/newsletterBG.jpg\') no-repeat;"><div style="position:relative;"><form id="simplenews-block-form-1" method="post" accept-charset="UTF-8" action="/subscribe"><input type="hidden" class="form-radio" checked="checked" value="subscribe" name="action" id="edit-action-subscribe"><input type="hidden" value="form-b1dec0b046548703ba3d8fc8baf7ed30" id="form-b1dec0b046548703ba3d8fc8baf7ed30" name="form_build_id"><input type="hidden" value="simplenews_block_form_1" id="edit-simplenews-block-form-1" name="form_id"><input type="text" name="first" style="font-size:16px;position:absolute;top:169px;left:33px;width:189px;height:27px;border:0px none;background:transparent;" /><input type="text" name="last" style="font-size:16px;position:absolute;top:169px;left:246px;width:189px;height:27px;border:0px none;background:transparent;" /><input type="text" name="mail" style="font-size:16px;position:absolute;top:229px;left:33px;width:402px;height:27px;border:0px none;background:transparent;" /><input type="submit" name="op" style="position:absolute;top:270px;left:150px;width:157px;height:41px;border:0px none;background:url(\'/images/newsletterSubmit.jpg\');color:transparent;cursor:pointer;" /></form></div></div>').fadeIn().addClass('curpage');
		    });
		} else if (page=='soundtrack') {
		    $('#contentWrapper').animateToClass('soundtrack',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.html('<iframe src="/node/156?framed=yes" width="800" height="400"></iframe>').fadeIn().addClass('curpage');
		    });
		} else if (page=='mahalos') {
		    $('#contentWrapper').animateToClass('mahalos',1500,'easeOutElastic',function(){
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    });
		} else if (page=='blog') {
    		if (subpage) {
	    		$('#blogFrame').html('<iframe src="/node/'+subpage+'?framed=yes" width="625" height="420"></iframe>');
	    		$('#blogMenu .active').removeClass('active');
	    		$('#blogMenu .blogTitle[nid='+subpage+']').addClass('active');
	    	}
		    $('#contentWrapper').animateToClass('blog',1500,'easeOutElastic',function(){
    			//if (subpage) {
		    	//	$('#blogFrame').html('<iframe src="/node/'+subpage+'?framed=yes" width="500" height="340"></iframe>');
			    //	$('#loading').delay(2000).fadeOut();
			    //	target.fadeIn().addClass('curpage');
		    	//} else {
			    	$('#loading').fadeOut();
			    	target.fadeIn().addClass('curpage');
		    	//}
		    });
	    	$('.blogTitle').click(function(){
	    	  var nid = $(this).attr('nid');
	    	  $('#blogFrame').html('<iframe src="/node/'+nid+'?framed=yes" width="625" height="420"></iframe>');
	    	  $('#blogContainer').show();
	    	});
		} else { 
		    var isnormal = $('#contentWrapper').hasClass('home');
		    if (isnormal) {
		    	$('#loading').fadeOut();
		    	target.fadeIn().addClass('curpage');
		    } else { 
		    	$('#contentWrapper').animateToClass('home',1500,'easeOutElastic',function(){
		    		$('#loading').fadeOut();
		    		target.fadeIn().addClass('curpage');
		    	});				
		    }
		    $('.blogTitle').click(function(){
		      var nid = $(this).attr('nid');
		      $('#blogFrame').html('<iframe src="/node/'+nid+'?framed=yes" width="625" height="420"></iframe>');
		      $('#blogContainer').show();
		    });
		}
	 }
	 
	 function loader(page,initial) {
       if (!page) { page = 'home'; }
       var pageOriginal = page;
       var thePages = page.split('/');
       if (thePages[1]) { 
         page = thePages[0];
  
         var curPage = $('.curpage').attr('id');
         if (curPage == page) {
           var exclude = new Array('','photos','blog');
           var excluded = $.inArray(page,exclude);         
         } else {
           var excluded = -1;
         }
  
       } else {
         var excluded = -1;
       }

       if (initial || excluded == -1) {
         $('.active').removeClass('active');
         $('.menuitem a[rel='+page+']').addClass('active');
         if (initial) {
             $('#contentWrapper').animateToClass(page,1500,'easeOutElastic',function(){
             	$('#menuWrapper').fadeIn(750,function(){
             		$('#content,#'+page).fadeIn(750,function(){
             			$('#footer').fadeIn(750,function(){
             				$('#menuBehind').show().animate({
             					right: "-33px",
             					top: "-170px"
             				}, 1000, 'easeOutBack', function(){
             				  $('#audioPlayer').fadeIn();
             				});
             			});
                 	});
                 	pages(pageOriginal);
                 });
             });
         } else {
             $('.curpage').fadeOut('slow',function(){
             	$('#loading').fadeIn();
             	$(this).removeClass('curpage');
             	pages(pageOriginal);
             });
         }       
       }
	 }
 	
 	// check for changed pages
 	var page;
    $(window).hashchange(function(){
      page = location.hash.substr(2);
      if (page) { loader(page); }
    });
    
    // check for incoming page
    $(window).hashchange();
    
    $('#edit-mail').attr('value','Email Address');
    $('#edit-submit').attr('value','Sign up for the Newsletter');
    
	$('#contentWrapper').fadeIn(750).animate({
//		padding: "20px",
		height: "25px",
		width: "150px"
	}, 750, 'easeOutElastic', function(){
		$('#logo').fadeIn();
	 	$('#logo img').animate({
	 		height: "102px",
	 		width: "200px"
	 	}, 750, 'easeOutElastic',function(){
				$('#loading').fadeIn('slow',function(){
					$(this).delay(2000);
					$('#loading').fadeOut('slow',function(){
//						if (page) {
							loader(page,'true');
//						} else {
//							loader(page);
//						}
					});
				});
	 	});
 	});
	$('.menuitem a, .clicker').bind('click',function(){
		$('.active').removeClass('active');
		$(this).addClass('active');
		//var newpage = $(this).attr('rel');
		//loader(newpage);
	});
 });
