(function($){
	//Scroll to the top (rather then jump)
	$('a[href=#container]').click(function(){
	    $('html, body').animate({scrollTop:0}, 'slow');
	    return false;
	});
	//Make placeholder work on all browers
	var initPlaceholder = function() {  
    	$('input[placeholder]').placehold();  
    };  
    if(!Modernizr.input.placeholder){  
		$(document).ready(initPlaceholder);  
	};
	
	if(document.getElementById("featured")) {
		setUpSlideShow();
	}
	
	if(document.getElementById("workTemplate")) {
		setUpSlideShowWork();
	}
	if(document.getElementById("home")) {
		setUpSlideShowHome();
	}
	
	
	if(document.getElementById("work")) {
		//work();
		setTimeout ( "work()", 2000 );
	}
	
	if(document.getElementById("clientsLogos")) {
		clients();
	}
	
	if(document.getElementById("aboutSlide")) {
		about();
	}
	
	
	
})(window.jQuery);

function setUpSlideShow() {
	var totalWidth=0;
	var num = 0;
	$('#featured #mask ul li').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		num ++;
	});
	//Set width
	totalWidth = Number((num * 980)+40);
	$('#featured #mask ul').width(totalWidth);
	
	//Create list
	$dots = $('<ul class="dots"></ul>')
	$('#controls').append($dots);
	for (var i = 0; i < (num); i++) {
		$lis = $('<li><a href="#" title=""></a></il>')
		$('#controls ul.dots').append($lis);
	}
	//set first item as active
	$('#controls ul.dots li:first-child').addClass("selected");
	
	$('#controls .dots li a').click(function(e){
		$('#controls .dots li').removeClass("selected");
		$(this).parent().addClass("selected");
		var button = $(this).parent().index();
		var scrollAmount = button * 981;
		changeText(button);
		scroll(scrollAmount);
		e.preventDefault();
	});
}




function scroll(x) {
	$('#featured #mask ul').stop().animate({marginLeft:-x+'px'},450);
}

function changeText(index) {
	var text = $('#featured #mask ul li:eq('+  index +')').find("img").attr("alt");
	$('#controls h2').text(text);
}


function setUpSlideShowWork() {
	var totalWidth=0;
	var num = 0;
	$('.project ul.slides li').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		num ++;
	});
	//Set width
	
	var amount = 640;
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
  		var w = window.innerWidth;
  		
  		amount = w;
	}
	
	totalWidth = Number((num * amount+100));
	$('.project ul.slides').width(totalWidth);
	
	
	
	$('.project ul.controls li a').click(function(e){
		$('.project ul.controls li').removeClass("selected");
		$(this).parent().addClass("selected");
		var button = $(this).parent().index();
		var scroll = button * amount;
		scrolltwo(scroll);
		e.preventDefault();
	});
}


function scrolltwo(x) {
	$('.project ul.slides').stop().animate({marginLeft:-x+'px'},450);
}

function work() {
	$("#lastestWork1 .mask").jCarouselLite({
   		auto: 2000,
   		visible: 1,
    	speed: 400
	});
	
	$("#lastestWork2 .mask").jCarouselLite({
   		auto: 3000,
   		visible: 1,
    	speed: 400
	});
}

function clients() {
	$("#clientsLogos").jCarouselLite({
   		auto: 2000,
   		visible: 3,
    	speed: 400
	});
}

function about() {
	$("#aboutSlide").jCarouselLite({
   		auto: 2000,
   		visible: 1,
    	speed: 400
	});
	
}




function setUpSlideShowHome() {
	var totalWidth=0;
	var num = 0;
	$('.project ul.slides li').each(function(i){
		/* Loop through all the slides and store their accumulative widths in totWidth */
		num ++;
	});
	//Set width
	
	var amount = 640;
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
  		var w = window.innerWidth;
  		
  		amount = w;
	}
	
	totalWidth = Number((num * amount));
	$('.project ul.slides').width(totalWidth);
	
	
	
	$('.project ul.controls li a').click(function(e){
		$('.project ul.controls li').removeClass("selected");
		$(this).parent().addClass("selected");
		var button = $(this).parent().index();
		var scroll = button * 300;
		scrolltwo(scroll);
		e.preventDefault();
	});
}

