	 /*						                        */
	/* global.js                                   */
   /* David Londono - http://www.reborn.com.au    */
  /*                                             */
macsafari = false;
mobile = false;

$(document).ready(function() {
	/* Cool Stuff when scrolling */
	win_height = $(window).height();
	
	if(!mobile){
		$(window).scroll(function() {
			bg_height = 1376;
			
			/* Parallax backgrounds control */		
			if(win_height > bg_height*0.8)
				bg_height = win_height*1.5;
				
			speed = (bg_height - win_height) / ($("#main").height() - win_height);
			pos = Math.round(speed * $(window).scrollTop())*-1;
			
			$("body").css("background-position", "50% "+pos+"px");
			
			if(!macsafari)
				$("#header .logo-bg").css("background-position", "50% "+pos+"px");
		});
	}
	
	// Correct last sections position for smooth scrolling
	correctScroll();
	
	// Same stuff when resizing
	$(window).resize(correctScroll);
	
	/* Read More button */
	$(".our_self .read_more a").click(function(event) {
		$(".our_self .read_more").hide();
		$(".our_self .extra").fadeIn("fast");
		
		event.preventDefault();
	});
	
	/* Newsletter Subscribe */
	$("#emailsub").focus(function() {
		if($(this).val() == $(this)[0].defaultValue)
			$(this).val('');
	}).blur(function() {
		if($(this).val() == '')
			$(this).val($(this)[0].defaultValue);
	});
	
	$("#news_subscribe").submit(function() {
		email = $("#emailsub").val();
		
		if(checkMail(email)) {
			$.post("newsletter_subscribe.php", { email: email }, function(data) {
				$("#nsres").html(data);
				
				$("#header .bottom .right").animate({width: "251px"}, "fast");
				$("#news_subscribe").fadeOut("fast");
				$("#nsres").delay("fast").fadeIn("fast");
				
				setTimeout(function() {
					$("#emailsub").val($("#emailsub")[0].defaultValue);
				}, 300);
			});
		}
		else {
			alert('Please enter a valid email address');
			$("#emailsub").focus();
		}
		
		return false;
	});
	
	/* Header Carousel */
	$('.lof-main-wapper').cycle({ 
		fx:		'fade',
		speed:  800,
		pause:	0,
		timeout: 4000,
		pager:	'#cnav', 
		next:   '#cnext', 
		prev:   '#cprev'
	});
	
	/* News Carousel */
	$('#slides').slides({
		preload: true,
		preloadImage: 'img/loading.gif',
		play: 0,
		pause: 2500,
		hoverPause: true
	});
	
	/* Case Studies */
	var thumbs = $("ul li img");			
	for (var i = 0, ii = thumbs.length; i < ii; i++){
		if (thumbs[i].title && thumbs[i].title.length > 0)
		{			
			var imgtitle = thumbs[i].title;		
			$(thumbs[i]).wrap('<div class="wrapper" />').				
			after('<div class=\'caption\'>' + imgtitle + '</div>').
			removeAttr('title');
		}					
	}

	$('.demo').hover(
		function(){
			$(this).find('img').animate({opacity: "1"}, 300);		
			$(this).find('.caption').animate({top:"-85px"}, 300);			
		}, 
		function(){
			$(this).find('img').animate({opacity: ".6"}, 300);					
			$(this).find('.caption').animate({top:"85px"}, 100);
		}		
	);
	
	$('.demo').hoverup({
		// You could set options in here too.
	});
	
	/* Menu page scrolling */
	$('.top_menu li a, .logo-bg a').click(function(event){
		scrollPage($(this).attr('href'));
		event.preventDefault();
	});
	
	/* PNG Fix */
	$('div.examples').pngFix( );
});

/* Page Smooth Scrolling */
function scrollPage(anchor) {	
	$('html, body').stop().animate({
		scrollTop: $(anchor).offset().top
	}, 1500, 'easeInOutQuint');
		
	setTimeout(function(){
		document.location = anchor;
	}, 1500);
}

function correctScroll() {
	win_height = $(window).height();
	
	cttop = win_height-301;
	$("#contact").css('margin-top', '-'+(cttop>180?cttop:180)+'px');
	
	mttop = win_height-535;
	$("#media").css('margin-top', '-'+(mttop>180?mttop:180)+'px');
}

/* Email validation */
function checkMail(email) {
	var x = email;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}




