$(document).ready(function(){   
	
	$(document).pngFix();
		
	$(".fancybox").fancybox({
		'titleShow': true,
		'titlePosition' : 'inside'
	});
	
	$(".fancyframe").fancybox({
		'width': 660,
		'height': 500
	});

	$(".foldouttoggle").click(function(){
	   $(this).parent().children(".foldoutbox").slideToggle("fast");
	   $(this).toggleClass("foldoutopen");
	});
	
	setTimeout("initscroller()", 100);
	
	setTimeout("newsscroller()", 100);
	
	$("#form1").validate({
		rules: {
			ename: "required",
			organisation: "required",
			email: "required",
			phone: "required",
			captcha: "required"
		},
		messages: {
			ename: "name - please complete",
			organisation: "organisation - please complete",
			email: "email - please complete",
			phone: "phone - please complete",
			captcha: "please enter the code"
		}
	});
	  
	$(".slideup").animate({top: '0'}, 500);
	
	$(".infooff, .moreoff").click(function(){
		$(".slideup").animate({top: '640px'}, 500);
		var href = $(this).attr('href');
		setTimeout(function() {window.location = href}, 500);
		return false;
	});
	
	initClicker();
		
});

function initClicker() {
		
	$(".rightarr").click(function(){
		$.getJSON($(this).attr("href").replace('work', 'ajax/work'), function(data) {	
			$("#worksectiona").html(data.worksectiona);
			$("#worksectionb").animate({left: '-600px'}, 500, function() {
				$("#worksectionb").html(data.worksectionb);
				$("#worksectionb").css("left", "600px");
				$("#worksectionb").animate({left: '0'}, 500);
			});
			$("#worksectionc").animate({opacity: '0'}, 200, function() {
				$("#worksectionc").html(data.worksectionc);
				$("#worksectionc").animate({opacity: '1'}, 200);
			});
			initClicker();
		});
		return false;
	});
	
	$(".leftarr").click(function(){
		$.getJSON($(this).attr("href").replace('work', 'ajax/work'), function(data) {
			$("#worksectiona").html(data.worksectiona);
			$("#worksectionb").animate({left: '600px'}, 500, function() {
				$("#worksectionb").html(data.worksectionb);
				$("#worksectionb").css("left", "-600px");
				$("#worksectionb").animate({left: '0'}, 500);
			});
			$("#worksectionc").animate({opacity: '0'}, 200, function() {
				$("#worksectionc").html(data.worksectionc);
				$("#worksectionc").animate({opacity: '1'}, 200);
			});
			initClicker();
		});
		return false;
	});
	
}


function initscroller() {
	// this initialises the demo scollpanes on the page.
	$('.scroll').jScrollPane({showArrows:true});
}

// news page scroller
function newsscroller() {
	$('#mycarousel').jcarousel({
       	vertical: true,
        scroll: 1
    });
}
