var loaderImg = '<img id="loader" src="img/loader.gif" alt="Loading..." />';

function mastheadLoad() {

	jQuery("#logo a, #nav li a").click(function() {
		jQuery('#masthead div.portfolio ul.page').scrollTo('0px',0);
	});

	jQuery("#home").click(function() {

		if ( !jQuery(this).hasClass("home") ) {					   

			jQuery("#box").fadeOut(200, function(){

				jQuery("#loader").show();

				jQuery("#box").load("http://southernmedia.net/wp-content/themes/southernmedia/presentation/?masthead=1", function() {	

					jQuery("#loader").hide();

					jQuery("#masthead").animate({ height: 378 }, 300, 'easeInOutCirc', function(){ jQuery("#box").fadeIn(200); mastheadLoad(); presentationLoad(); });
					
				});
				
			});
		
		}
	
		jQuery("#home").addClass('home');	
		
		jQuery("#navServices").removeClass('active');
		
		jQuery("#navPortfolio, .portfolio-link").removeClass('active');
		
		jQuery("#navContact").removeClass('active');
		
		return false;
			
	});	
	
	jQuery("#btnServices").click(function() {							  
										  
		if ( !jQuery(this).parent().hasClass("active") ) {
														  
			jQuery("#box").fadeOut(200, function(){

				jQuery("#loader").show();
	
				jQuery("#box").load("http://southernmedia.net/wp-content/themes/southernmedia/services/?masthead=1", function() {

					jQuery("#loader").hide();

					jQuery("#masthead").animate({ height: 378 }, 300, 'easeInOutCirc', function(){ jQuery("#box").fadeIn(200); mastheadLoad(); servicesLoad(); });
					
				});
				
			});
		
		}
	
		jQuery("#navServices").addClass('active');
		
		jQuery("#navPortfolio, .portfolio-link").removeClass('active');
		
		jQuery("#navContact").removeClass('active');
		
		jQuery("#home").removeClass('home');	
		
		return false;
			
	});
	
	jQuery("#btnPortfolio").click(function() {
				
		if ( !jQuery(this).parent().hasClass("active") ) {
				
			jQuery("#box").fadeOut(200, function(){
												 
				jQuery("#loader").show();
	
				jQuery("#box").load("http://southernmedia.net/wp-content/themes/southernmedia/portfolio/?masthead=1", function() {
					
					jQuery("#loader").hide();
															  
					jQuery("#masthead").animate({ height: 665 }, 300, 'easeInOutCirc', function(){ jQuery("#box").fadeIn(200); mastheadLoad(); portfolioLoad(); });
					
				});
				
			});
			
		}
			
		jQuery("#navServices").removeClass('active');
		
		jQuery("#navContact").removeClass('active');
		
		jQuery("#navPortfolio, .portfolio-link").addClass('active');
		
		jQuery("#home").removeClass('home');
		
		return false;
			
	});


	/* Scroll up
	---------------------*/

	jQuery("#latestWork p a.portfolio-link").click(function() {

		if ( !jQuery(this).hasClass("active") ) {

			jQuery("#box").fadeOut(200, function(){

				jQuery("#loader").show();

				jQuery("#box").load("http://southernmedia.net/wp-content/themes/southernmedia/portfolio/?masthead=1", function() {

					jQuery("#loader").hide();

					jQuery("#masthead").animate({ height: 665 }, 300, 'easeInOutCirc', function(){ jQuery("#box").fadeIn(200); mastheadLoad(); portfolioLoad(); });
					
				});
				
			});
			
		}
		
		jQuery("#navPortfolio, .portfolio-link").addClass('active');
		
		jQuery.scrollTo('0px',500);
		
		return false;

	});
	
	jQuery("#btnContact, .contact-link").click(function() {
				
		if ( !jQuery(this).parent().hasClass("active") ) {
				
			jQuery("#box").fadeOut(200, function(){
				
				jQuery("#loader").show();
	
				jQuery("#box").load("http://southernmedia.net/wp-content/themes/southernmedia/contact/?masthead=1", function() {
					
					jQuery("#loader").hide();
															  
					jQuery("#masthead").animate({ height: 378 }, 300, 'easeInOutCirc', function(){ jQuery("#box").fadeIn(200); mastheadLoad(); contactLoad(); });
					
				});
				
			});
			
		}
			
		jQuery("#navServices").removeClass('active');
		
		jQuery("#navPortfolio, .portfolio-link").removeClass('active');
		
		jQuery("#navContact").addClass('active');
		
		jQuery("#home").removeClass('home');
	
		return false;	
			
	});

}

mastheadLoad();


function servicesLoad() {

	jQuery('#masthead ul.masthead-nav').show();

	jQuery('#masthead .widearea')
	.cycle({ 
		fx: 'scrollHorz',
		speedIn: 400,
		speedOut: 400,
		timeout: 0
	});

	jQuery('#masthead .web').click(function() { 
		jQuery('#masthead .widearea').cycle(0);
		return false;
	}); 

	jQuery('#masthead .css').click(function() {  
		jQuery('#masthead .widearea').cycle(1);
		return false;
	});

	jQuery('#masthead .wordpress').click(function() {  
		jQuery('#masthead .widearea').cycle(2);
		return false;
	});

}


function presentationLoad() {

	jQuery('#masthead ul.masthead-nav').show();

	jQuery('#masthead .widearea')
	.cycle({ 
		fx: 'scrollHorz',
		speedIn: 400,
		speedOut: 400,
		timeout: 0,
		next: '#presentation .next',
		prev: '#presentation .back'
	});

} presentationLoad();


function contactLoad() {

	var loaderImg = '<img id="loader" src="img/loader.gif" alt="Loading..." />';
	
	jQuery("#contactFormContent").append(loaderImg);						
							
	//$("#loader").hide();
	
	function loadForm() {

		jQuery("#contactSubmit").click(function(){
												
			jQuery("#contactFormContent").fadeOut(300, function(){
																																						 
				//jQuery("#loader").show();
														 
				jQuery.post("http://southernmedia.net/wp-content/themes/southernmedia/submit.php", { name: jQuery("[name=name]").val(), email: jQuery("[name=email]").val(), subject: jQuery("[name=subject]").val(), comments: jQuery("[name=comments]").val(), submit: jQuery("[name=submit]").val() }, function(data) {	
	
					jQuery("#contactFormContent").html(data);
					
					//jQuery("#loader").hide();
	
					jQuery("#contactFormContent").fadeIn(300);
					
					loadForm();
	
				});

			});

			return false;

		});

	}

	loadForm();

}


function portfolioLoad() {


 	/* Fancybox img
	---------------------*/
	
	jQuery("#masthead div.portfolio ul.page > li > div.info ul li a[title]").fancybox({
		'zoomOpacity': true,
		'overlayShow': true,
		'overlayOpacity': 0.7,
		'hideOnContentClick': false,
		'centerOnScroll': false
	});


	/* Fancybox iframe
	---------------------*/

	jQuery("#masthead div.portfolio ul.page > li > div.info ul li a.iframe").fancybox({
		'zoomOpacity': true,
		'overlayShow': true,
		'overlayOpacity': 0.7,
		'hideOnContentClick': false,
		'centerOnScroll': true,
		'frameWidth': jQuery(window).width()-60,
		'frameHeight': jQuery(window).height()-60
	});


	/* Portfolio Info
	---------------------*/

	jQuery('#masthead div.portfolio ul.page > li').mouseover(function() { jQuery(this).children('.info').stop().animate({"top":'0'}, 100); });

	jQuery('#masthead div.portfolio ul.page > li').mouseout(function() { jQuery(this).children('.info').stop().animate({"top":'160px'}, 300); });


	/* Portfolio Filter
	---------------------*/

	function showWork(c) {
		jQuery('#masthead ul.page > li.' + c).show();
		jQuery('#masthead ul.page > li:not(.' + c + ')').hide();
	}

	jQuery('#portfolioNav > li > a, #masthead ul.page > li > div.info p.categories a').click(function(){
		var the_class = $(this).attr('class');

		if (the_class == 'all') {
			jQuery('#masthead ul.page > li').show();
		} else {
			showWork( the_class );
		}

		jQuery('#portfolioNav > li').removeClass('active');
		jQuery(this).parent('li').addClass('active');
		
		/*startScrollControls();*/

		jQuery('#masthead div.portfolio ul.page').scrollTo('0px',0);
		
		return false;

	}); jQuery('#masthead div.portfolio ul.page').scrollTo('0px',0);


	/* Portfolio Scroll
	---------------------*/

	jQuery('#paginationNav li.next a').click(function() { jQuery('#masthead div.portfolio ul.page').scrollTo('+=170px',400); return false; });

	jQuery('#paginationNav li.prev a').click(function() { jQuery('#masthead div.portfolio ul.page').scrollTo('-=170px',400); return false; });

}
