$(document).ready( function($) {
		
	simpleSlide({'swipe':'true'});
	addNotranslate();
		
	$('.slideshow').live('mouseover mouseout', 
		function(event) {
			if(event.type == 'mouseover'){
				$(this).children('.left-button, .right-button').stop(true, true).fadeIn();
			}
			else {
				$(this).children('.left-button, .right-button').stop(true, true).fadeOut();
			}
		}
	);
	
	$('.auto-slider').each( function() {							 
		var related_group = $(this).attr('rel');
		clearInterval($.autoslide);
		$.autoslide = setInterval("simpleSlideAction('.right-button', " + related_group + ");", 4000);
	});	

	// Custom GA tracking event: AJAX Page Loads
		
	$('#nav_links li').live( 'click', function() {
		var page_name = $(this).attr('rel');
				
		pageTracker._trackEvent('Pages', 'Views', page_name);
	});

	$('.right-button, .left-button').live( 'click', function() {
		var action = $(this).attr('class');
				
		pageTracker._trackEvent('Slide Interactions', 'Clicks', action);
	});

	$('#bigboy, #mini').live( 'click', function() {
		var version = $(this).attr('id');
				
		pageTracker._trackEvent('simpleSlide Downloads', 'Downloaded', version);
	});

});

function navColors(color_name){	
	$('ul#nav_links li').removeAttr('class');

	$('ul#nav_links li span').each( function() {
		if( $(this).attr('class') == color_name) {
			$(this).parent().addClass(color_name);
		}
	});
}

function addNotranslate() {
	$('.codeblock').addClass('notranslate');
	$('code').addClass('notranslate');
}




$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var website = $('input[name=website]');
		var comment = $('textarea[name=comment]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		if (name.val()=='') {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');
		
		if (email.val()=='') {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');
		
		if (comment.val()=='') {
			comment.addClass('hightlight');
			return false;
		} else comment.removeClass('hightlight');
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&website=' + 
		website.val() + '&comment='  + encodeURIComponent(comment.val());
		
		//disabled all the text fields
		$('.text').attr('disabled','true');
		
		//show the loading sign
		$('.loading').show();
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "process.php",	
			
			//GET method is used
			type: "GET",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {				
				//if process.php returned 1/true (send mail success)
				if (html==1) {					
					//hide the form
					$('.form').fadeOut('slow');					
					
					//show the success message
					$('.done').fadeIn('slow');
					
				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');				
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	
