$(document).ready(function() {
	$("#overlay").css("opacity","0.70");			   
	
	$("#newsletter").click(function () {
		$("#overlay").toggle();
		$("#newsletter-wrapper").toggle();
		$("#nav").toggle();
	});
	
	$("#newsletter-box .close").click(function () {
		$("#overlay").toggle();
		$("#newsletter-wrapper").toggle();
		$("#nav").toggle();
	});
	
	var i = 1;
	
	$(".response .yes").click(function () {
		if (i == 1) {
			$(".q1").hide();
			$(".q2").show();			
			i++;
		} else if (i == 2) {
			$(".q2").hide();
			$(".q3").show();
			i++;
		}
		else {
			location.href = "/home";
			$.cookie('commune', 'skip', { expires: 30, path: '/' });
		}
		
	});
	
	$(".response .no").click(function () {		
		$(".question").hide();
		$(".response").hide();
		$(".skip").hide();
		
		if (i == 1) {
			$(".answer").show();			
			i++;
		} else if (i == 2) {
			$(".a1").hide();
			$(".a2").show();
			$(".answer").show();			
			i++;
		}
		else if (i == 3) {
			$(".a1").hide();
			$(".a2").hide();
			$(".a3").show();
			$(".answer").show();
		}
		
	});
	
	$("#newsletterForm").submit(function () {
		var reg=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    
		if(reg.test($(".emailForm"))) {         
			return true;		
    	}
		else {
			alert("Please ensure your email is correct!");
			return false;
		}
		
		return true;
	});
	
	$(".skip a").click(function () {		
		$.cookie('commune', 'skip', { expires: 30, path: '/' });		
	});
	
	$(".answer a").click(function () {		
		$.cookie('commune', 'skip', { expires: 30, path: '/' });		
	});
	
	$(".commune_intro").click(function () {		
		$.cookie('commune', 'skip', { expires: 30, path: '/' });		
	});
	
	$('#thumbnails').serialScroll({
		items:'li',
		prev:'#image-nav .prev',
		next:'#image-nav .next',
		duration:400,
		force:true,
		stop:true,
		lock:false,
		cycle:true
	});
	
	$("#thumbnails img").live("click", function () {
		id = $(this).attr("rel");
		id = (id.replace(/t-/, ""));
		
		$("#work-image img").remove();
		$("#work-image").append('<div class="ajax"><img src="/images/ajax.gif" alt="Loading..." /> Loading...</div>');
		
		$.get("/the-work/get/id/"+id, function(data) {			
			$("#work-image").append(data);
			$(".ajax").remove();
   		});
		
		/*
		$.get("/the-work/info/id/"+id, function(data) {			
			$("#work-info div").remove();
			$("#work-info").append(data);
   		});
		*/
	});
	
	$("#clients a").click(function () {
		id = $(this).attr("rel");
		id = (id.replace(/c-/, ""));
		
		$("#workContainer div").remove();
		$("#workContainer").append('<div class="ajax"><img src="/images/ajax.gif" alt="Loading..." /> Loading...</div>');
		
		$.get("/the-work/get-client/id/"+id, function(data) {			
			$("#workContainer").append(data);
			$(".ajax").remove();
   		});
		
		return false;
	});
	
	$(".testimonial span").click(function () {
		id = $(this).attr("rel");
		
		$(".testimonial .full").hide();
		$(".testimonial .extract").show();
		
		$("#e-"+id).slideUp();
		$("#t-"+id).fadeIn();
	});
	
	$(".clientstable input").click(function () {
		state = $(this).attr("class");
		id = $(this).attr("rel");
		
		$.get("/admin/featured/id/"+id+"/state/"+state, function(data) {			
			alert(data);
   		});
	});
	
	$(".exp-cat").hover(function () {
    	rel = $(this).attr("rel");		
		$("#"+rel).fadeIn('slow');
  	}, function () {
		rel = $(this).attr("rel");		
		$("#"+rel).hide();
	});

});

jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000))}else{date=options.expires}expires='; expires='+date.toUTCString()}var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('')}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break}}}return cookieValue}};