$(document).ready(function(){
	$('#password').hide();
	$('#password_fake').show();
	$('#username').focus(function(){if($(this).val() == 'Username')$(this).val('');});
	$('#password_fake').focus(function(){
		$(this).hide();
		$('#password').show().focus();
	});
	$('#username').blur(function(){if($(this).val() == '')$(this).val('Username');});
	$('#password').blur(function(){
		if($(this).val() == '')
		{
			$(this).hide();
			$('#password_fake').show();
		}
	});
	
	$('p a').click(function(){
		
		switch($(this).attr('href'))
		{
			case '/home':
				$('#home h1').trigger('click');
				return false;
			case '/about':
				$('#about h1').trigger('click');
				return false;
			case '/films':
				$('#films h1').trigger('click');
				return false;
			case '/investors':
				$('#investors h1').trigger('click');
				return false;
		}
	});
	
	var homeHeight = 640;
	var filmsHeight = 603;
	if($(window).height() < 700)
	{
		homeHeight = 565;
		filmsHeight = 575;
		$('#wrapper').css('padding-top',0);
		$('#inner_wrapper').css('margin-top','7px');
		$('#home.home').height(homeHeight);
		$('#films.films').height(filmsHeight);
		$('#films.films h2').css('padding-top',0);
	}
	
	$('#name').focus(function(){if($(this).val() == 'Name')$(this).val('');});
	$('#email').focus(function(){if($(this).val() == 'Email')$(this).val('');});
	$('#phone').focus(function(){if($(this).val() == 'Phone')$(this).val('');});
	$('#message').focus(function(){if($(this).html() == 'Message')$(this).html('');});
	$('#name').blur(function(){if($(this).val() == '')$(this).val('Name');});
	$('#email').blur(function(){if($(this).val() == '')$(this).val('Email');});
	$('#phone').blur(function(){if($(this).val() == '')$(this).val('Phone');});
	$('#message').blur(function(){if($(this).html() == '')$(this).html('Message');});
	
	
	//investor scroller
//	$('#investors_text_inner').width(3000);
//	$('#investors_text_inner').height(3000);
//	//$('#scroller').show();
//	$('#investors_text_inner').animate({scrollTop:'-=300px'},1000);
//	//$('#investors_text_inner').scrollTo( '+=340px', { axis:'y',duration:1000} );
//	$('#up').click(function(){
//		$('#investors_text').scrollTo( 150, 800 );
//	});
//	$('#down').click(function(){
//	});
//	
	
	//box animation


	var homeActive = {height:homeHeight,width:660,left:'0px',top:'0px'};
	var homeAboutInactive = {height:130,width:130,left:'660px',top:'30px'};
	var homeFilmsInactive = {height:103,width:103,left:'734px',top:'160px'};
	var homeInvestorsInactive = {height:88,width:88,left:'837px',top:'223px'};
	
	var aboutActive = {height:605,width:560,left:'125px',top:'0px'};
	var aboutHomeInactive = {height:125,width:125,left:'0px',top:'23px'};
	var aboutFilmsInactive = {height:110,width:110,left:'685px',top:'70px'};
	var aboutInvestorsInactive = {height:88,width:88,left:'795px',top:'130px'};

	var filmsActive = {height:filmsHeight,width:603,left:'166px',top:'0px'};
	var filmsHomeInactive = {height:86,width:86,left:'0px',top:'43px'};
	var filmsAboutInactive = {height:80,width:80,left:'86px',top:'103px'};
	var filmsInvestorsInactive = {height:100,width:100,left:'769px',top:'198px'};

	var investorsActive = {height:548,width:548,left:'216px',top:'0px'};
	var investorsHomeInactive = {height:85,width:85,left:'0px',top:'33px'};
	var investorsAboutInactive = {height:95,width:95,left:'85px',top:'73px'};
	var investorsFilmsInactive = {height:77,width:77,left:'139px',top:'168px'};
	
	var active;
	var oldActive;
	if($('#home').hasClass('home')){active = 'home';}
	if($('#home').hasClass('about')){active = 'about';}
	if($('#home').hasClass('films')){active = 'films';}
	if($('#home').hasClass('investors')){active = 'investors';}
	var aniDone = false;
	var aniOptionsOnce = {duration:'slow',
			easing:'swing',
			complete:function(){
		
				$('#home,#about,#films,#investors').removeClass(oldActive);
				$('#home,#about,#films,#investors').addClass(active);
				if($(window).height() < 900)
				{
					$('#films.films h2').css('padding-top',0);
				}
				Cufon.refresh();
				$('#'+active).find('.inner_holder').fadeIn('slow',function(){this.style.removeAttribute('filter');});
				$('#home.about h1,#home.films h1,#home.investors h1,#about h1,#films h1,#investors h1').fadeIn('slow',function(){this.style.removeAttribute('filter');});
				
			}
	};
	var aniOptions = {duration:'slow',
						easing:'swing'
					};
	$('h1').click(function(){
		aniDone = false;
		oldActive = active;
		active = $(this).parent().attr('id');
		$('.inner_holder:visible').fadeOut('slow',function(){this.style.removeAttribute('filter');});
		//$('#twitter:visible').slideUp('slow');
		$('#home h1:visible,#about h1,#films h1,#investors h1').fadeOut('slow',function(){
			if(!aniDone)
			{
				aniDone = true;
				switch(active)
				{
					case 'home':
						$('#home').animate(homeActive,$.extend( true, [], aniOptions));
						$('#about').animate(homeAboutInactive,$.extend( true, [], aniOptions));
						$('#films').animate(homeFilmsInactive,$.extend( true, [], aniOptions));
						$('#investors').animate(homeInvestorsInactive,$.extend( true, [], aniOptionsOnce));
						break;
					case 'about':
						$('#home').animate(aboutHomeInactive, $.extend( true, [], aniOptions) );
						$('#about').animate(aboutActive,$.extend( true, [], aniOptions));
						$('#films').animate(aboutFilmsInactive,$.extend( true, [], aniOptions));
						$('#investors').animate(aboutInvestorsInactive,$.extend( true, [], aniOptionsOnce));
						break;
					case 'films':
						$('#home').animate(filmsHomeInactive,$.extend( true, [], aniOptions));
						$('#about').animate(filmsAboutInactive,$.extend( true, [], aniOptions));
						$('#films').animate(filmsActive,$.extend( true, [], aniOptions));
						$('#investors').animate(filmsInvestorsInactive,$.extend( true, [], aniOptionsOnce));
						break;
					case 'investors':
						$('#home').animate(investorsHomeInactive,$.extend( true, [], aniOptions));
						$('#about').animate(investorsAboutInactive,$.extend( true, [], aniOptions));
						$('#films').animate(investorsFilmsInactive,$.extend( true, [], aniOptions));
						$('#investors').animate(investorsActive,$.extend( true, [], aniOptionsOnce));
						break;
				}
				Cufon.refresh();
			}
		});
		
		return false;
	});
});
