$(document).ready(function(){

	// initialise header carousel	
	$('#carousel ul.items').before('<div id="nav">').cycle({ 
		fx: 'fade', 
		speed: 'slow', 
		timeout: 6000,
		pager: '#nav'
	});
	
	$('#carousel #nav').append('<a href="#" class="play off">play<\/a><a href="#" class="pause">pause<\/a>');
	$('#carousel #nav a.pause').click(function() { 
		$('#carousel ul.items').cycle('pause');
		$(this).addClass('off');
		$(this).parent().find('a.play').removeClass('off');
		return false;
	});

	$('#carousel #nav a.play').click(function() { 
		$('#carousel ul.items').cycle('resume', true);
		$(this).addClass('off');
		$(this).parent().find('a.pause').removeClass('off');
		return false;
	});
	
	// sidebar toggles
	$("li.appSlide1").click(function(){
		$("li.appPanel1").slideToggle("slow");
		$(this).toggleClass("active");
		return false;
	});

	$("li.appSlide2").click(function(){
		$("li.appPanel2").slideToggle("slow");
		$(this).toggleClass("active");
		return false;
	});

	$("li.appSlide3").click(function(){
		$("li.appPanel3").slideToggle("slow");
		$(this).toggleClass("active");
		return false;
	});
					
	if (window.location.pathname.match(/(appstar)/) || window.location.pathname.match(/(summer-of-widgets)/) || window.location.pathname.match(/(betavine)/)) {
		$("li.appPanel4").show();
		$("li.appSlide4").click(function(){
			$("li.appPanel4").slideToggle("slow");
			$(this).toggleClass("active");
			return false;
		});
	} else {
		$("li.appSlide4").click(function(){
			$("li.appPanel4").slideToggle("slow");
			$(this).toggleClass("active");
			return false;
		});
	};	
			
	$("li.talkSlide").click(function(){
		$("li.talkSlide").removeClass("talkSlideBorder");
		$("li.talkPanel").slideToggle("slow")
		$(this).toggleClass("active");
		return false;
	});
			
	// More Clients interaction
	var moreClientsState = $.cookie("moreClientsState");
	if(!moreClientsState || moreClientsState == "closed") {
		$.cookie("moreClientsState", "closed", { path: '/', expires: 10000 });
		$('.allClients').hide();
	}
	else {
		$('#moreOrLessClients').removeClass("moreAppsIcon").addClass("lessAppsIcon");
		$(this).toggleClass("active");
	}
	$('#moreOrLessClients').click(function() {
		var moreClientsState = $.cookie("moreClientsState");
		$.cookie("moreClientsState", (moreClientsState == "open") ? "closed" : "open", { path: '/', expires: 10000 });
		$('.allClients').slideToggle("slow", function() {
			$('#moreOrLessClients').toggleClass("moreAppsIcon").toggleClass("lessAppsIcon");
			$(this).toggleClass("active");
		});
		return false;
	});
			
	// More Apps interaction
	var moreAppsState = $.cookie("moreAppsState");
	if(!moreAppsState || moreAppsState == "closed") {
		$.cookie("moreAppsState", "closed", { path: '/', expires: 10000 });
		$('.allApps').hide();
	}
	else {
		$('#moreOrLess').removeClass("moreAppsIcon").addClass("lessAppsIcon");
		$(this).toggleClass("active");
	}
	$('#moreOrLess').click(function() {
		var moreAppsState = $.cookie("moreAppsState");
		$.cookie("moreAppsState", (moreAppsState == "open") ? "closed" : "open", { path: '/', expires: 10000 });
		$('.allApps').slideToggle("slow", function() {
			$('#moreOrLess').toggleClass("moreAppsIcon").toggleClass("lessAppsIcon");
			$(this).toggleClass("active");
		});
		return false;
	});
	
	// initialise easy slider
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		allControls: true,
		onhover: true,
		pause:3000
	});
	
	//Initialize our user agent string to lower case.
	var deviceIphone = "iphone";
	var deviceIpod = "ipod";	
	
	var uagent = navigator.userAgent.toLowerCase();		
	
	if (uagent.search(deviceIphone || deviceIpod) > -1) {
		return true
	} else {
		$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'dark_rounded',
			default_width: 480,
			default_height: 295,
			show_title: false
		});	
	};
		
				

});
