$(document).ready(function(){

	/* 
	//	General Definations
	*/
		// Global Variables
		var lastNavItem = "top";

		// Get window height and width
		var windowHeight = $(window).height();
		var windowWidth = $(window).width();
		
		var headerHeight = $('#header').outerHeight();
		
		//	Set min height to section areas
		$('div.section').css('min-height',(windowHeight-headerHeight));
	
	/* 
	//	Button Definations
	*/
	     $('#about .button a').button();
	  
	/* 
	//	Cufon Definations
	*/

		// If you don't want to use cufon, please comment or remove code below
		Cufon.replace('div.section h1, div.section h2, div.section h3, div.section h4');
		Cufon.replace('div.section div.section-heading h1', {textShadow: '1px 1px #000'});


	/* 
	//	Pretty Photo Definations
	*/	
	
				

	

	/* 
	//	Cycle Slider Definations
	*/

		// Row number which is how much row showing in slider
		var rowNumber = 2;
		
		$('div.portfolio-slider').each(function(i) {
			
			var _this = $(this);
			var maxItemHeight = 0;
			
			_this.find('div.portfolio-item').each(function() {
				if($(this).height() > maxItemHeight) {
					maxItemHeight = $(this).outerHeight(true);
				};
			})													

			_this.css({'height':(maxItemHeight*rowNumber)})

			if(_this.find('div.portfolio-list').length > 1) {
				_this.after('<div class="portfolio-nav">').before('<div class="portfolio-nav">');
				_this.cycle({
					fx: 'scrollLeft',
					speed:  'slow', 
					timeout: 0, 
					pager:  _this.siblings('div.portfolio-nav')
				});
			}

		})

	/* 
	//	Piecemaker Definations
	*/

      var flashvars = {};
      flashvars.cssSource = "assets/piecemaker/piecemaker.css";
      flashvars.xmlSource = "assets/piecemaker/piecemaker.xml";
		
      var params = {};
      params.play = "true";
      params.menu = "false";
      params.scale = "showall";
      params.wmode = "transparent";
      params.allowfullscreen = "true";
      params.allowscriptaccess = "always";
      params.allownetworking = "all";
	  
      swfobject.embedSWF('assets/piecemaker/piecemaker.swf', 'flash-slider', '980', '603', '10', null, flashvars, params, null);

	/* 
	// 	Main Navigation Definations
	*/

		$('ul.navigation li a').live('click',function(event){
			event.preventDefault();
			var id = $(this).attr('href');
			$.scrollTo(id, 800, {offset:-headerHeight});
			lastNavItem = id;
		})
		
		// Sub Navigagation Definations
		$('ul.navigation > li').hover(
			function(){
				$(this).stop().find('ul').fadeIn();
			},
			function(){
				$(this).find('ul').fadeOut();	
			}
		)

	/* 
	//	Portfolio Definations
	*/
	
		// Porfolio Item Hover Behaviour
		$('div.portfolio-item').hover(
			function(){
				$(this).find('img').stop().animate({opacity:0.5});					  
			},
			function(){
				$(this).find('img').stop().animate({opacity:1});					  
			}
		)

	/* 
	//	Form Definations
	*/
		
		// Submit Event
		$('#contact-form a.button').click(function(event) {
			event.preventDefault();
			$('#contact-form form').submit();
		})

	/* 
	// 	Social Network Definations
	*/	
	
		$('#social-network').find('img').css({'opacity':0.6});
		
		$('#social-network').find('img').hover(
			function(){
				$(this).stop().animate({opacity:1})
			},
			function(){
				$(this).stop().animate({opacity:0.6})
			}
		)

	/* 
	// 	Contact Form Definations
	*/	

		$('#contact-form a.button').click(function(e){
			e.preventDefault();
			$('#contact-form').submit();
		})
	
		// Do what we need to when form is submitted.
		$('#contact-form').submit(function(){
		
		// Setup any needed variables.
		var input_name = $('#c-name').val(),
			input_surname = $('#c-surname').val(),
			input_email = $('#c-email').val(),
			input_subject = $('#c-subject').val(),
			input_message = $('#c-message').val(),
			response_text = $('#c-response');
			
			// Hide any previous response text
			response_text.hide();
	
			// Change response text to 'loading...'
			response_text.html('Loading...').show();
	
			// Make AJAX request
			$.post('assets/contactForm/contact-send.php', {name: input_name, surname: input_surname, email: input_email, subject: input_subject, message: input_message}, function(data){
				response_text.html(data);
			});
	
			// Cancel default action
			return false;
		});


	/* 
	// 	Window Resize Events
	*/		

	var _time = null;

	$(window).resize(function() {
		var headerHeight = $('#header').outerHeight();
		clearTimeout(_time);
		
		_time = setTimeout(function() {
			
			windowHeight = $(window).height();
			windowWidth = $(window).width();
			
			$('div.section').css('min-height',(windowHeight-headerHeight));
			
			$.scrollTo(lastNavItem, 800, {offset:-headerHeight});
			
		},800)
		
	})
									   
})
