// Assign values
var path			= "/wp-content/themes/p203/images/";

var img1 			= path+"top1.jpg";
var img2 			= path+"top2.jpg";
var img3 			= path+"top3.jpg";
//var img4 			= path+"top4.jpg";

var active			= path+"button_active.gif";
var unactive		= path+"button_unactive.gif";

var n_enabled		= path+"next.gif";
var n_disabled		= path+"next_disabled.gif";

var p_enabled		= path+"prev.gif";
var p_disabled		= path+"prev_disabled.gif";

var startAutoSlide	= "";
var autoTimeout		= "";

var ie				= false;
if($.browser.msie){
	ie = true;
}


// Assign text and images
var h1_1 = "”Ni är mycket engagerade och smidiga att jobba med, PRODUKTION203 anstränger sig verkligen det där lilla extra. Tack!”";
var h1_2 = "”Som gammal interneträv gillar jag den unga och nyfikna attityd till nya kreativa lösningar som är så typiskt för PRODUKTION203.”";
var h1_3 = "En riktig webbyrå i Stockholm";
//var h1_4 = " ";

var h2_1 = "- Frida Klevemark, Produktchef Hemmakanalen TV4";
var h2_2 = "- Pelle Lindberg, VD Millerspath";
var h2_3 = "PRODUKTION203 - Vi VET hur du lyckas på internet!";
//var h2_4 = " ";

var comimg1 = path+"tv4.gif";
var comimg2 = path+"artistkatalogen.gif";

var link1	= "referenser/tv4-hemmakanalen-se.html";
var link2	= "referenser/artistkatalogen.html";
var link3	= "referenser/"
//var link4	= "http://design.produktion203.se/"


$(document).ready(function(){
	if(document.location == "http://www.produktion203.se/" || document.location == "http://produktion203.se/" || document.location == "http://p203-word.henrikb.p203.se/"){
		// Add first button active
		$("#b1 img").attr("src", active);
		
		// Add first text & images
		
		$("#rubrik_h1").text(h1_1);
		$("#rubrik_h2").text(h2_1);
		$("#comimg").attr("src", comimg1);
		$("#rubrik a").attr("href",link1);
		
		if(ie == true){
			$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/tv4text.jpg")', "height" : "150px"});
		}
		
		// Start autoslide function after 10 sec
		startAutoSlide = setTimeout("autoSlide()", 10000);
		
		// On click, clear the timeouts and show correct image and text
		$("#b1 img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); image1(); });
		$("#b2 img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); image2(); });
		$("#b3 img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); image3(); });
		//$("#b4 img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); image4(); });
		
		// On click next or prev, clear timeouts and go +1 or -1
		$("#next img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); next(); });
		$("#prev img").click(function(){ clearTimeout(autoTimeout); clearTimeout(startAutoSlide); prev(); });
	}
});



// Autosliding all images and texts
function autoSlide(){
	if($("#largeImage").attr("src") == img1){
		image2();
	} else if($("#largeImage").attr("src") == img2){
		image3();
	/*} else if($("#largeImage").attr("src") == img3) {
		image4();*/
	} else {
		image1();
	}
	
	autoTimeout = setTimeout("autoSlide()", 10000);	
}
// FUNCTION autoSlide END



// If image 1 click
function image1(){
	
		// If current not same as click check
		if($("#largeImage").attr("src") != img1){
		
			// Animate out
			$("#largeImage").stop().animate({marginLeft: "-500px"}, function(){
				
				// Change content
				$("#largeImage").attr("src",img1).css({"margin-left" : ""});
				$("#largeImage").unbind("click").css("cursor", "default");
				$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
				$("#rubrik_h1").text(h1_1).addClass("case").removeClass("p203");
				$("#rubrik_h2").text(h2_1);
				$("#logoButton img").css({"display" : "inline"})
				$("#comimg").attr("src", comimg1);
				$("#logoButton a").css({"display" : "inline"}).attr("href",link1);
				$("#rubrik a").attr("href",link1);
				
				if(ie == true){
					$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/tv4text.jpg")', "height" : "150px"});
				}
				
				// Fade in text
				$("#rubrik").fadeIn();
				$("#logoButton").fadeIn();
				
				// Set button availability
				$("#b2 img").attr("src", unactive);
				$("#b3 img").attr("src", unactive);
				$("#b1 img").attr("src", active);
				//$("#b4 img").attr("src", unactive);
				
				// Set arrow availability
				$("#prev img").attr("src", p_disabled);
				$("#next img").attr("src", n_enabled);
				
			});
			
			// Fade out text
			$("#rubrik").fadeOut();
			$("#logoButton").fadeOut();
			
			// Animate in
			$("#largeImage").animate({
				marginLeft: "50px"
			}, {
				duration: 1000,
				easing: 'easeOutExpo'
			});
		}
	
}
// FUNCTION image1 click



// If image 2 click
function image2(){
	
		// If current not same as click check
		if($("#largeImage").attr("src") != img2){
		
			// Animate out
			$("#largeImage").stop().animate({marginLeft: "-500px"}, function(){
				
				// Change content
				$("#largeImage").attr("src",img2).css({"margin-left" : ""});
				$("#largeImage").unbind("click").css("cursor", "default");
				$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
				$("#rubrik_h1").text(h1_2).addClass("case").removeClass("p203");
				$("#rubrik_h2").text(h2_2);
				$("#logoButton img").css({"display" : "inline"});
				$("#comimg").attr("src", comimg2);
				$("#logoButton a").css({"display" : "inline"}).attr("href",link2);
				$("#rubrik a").attr("href",link2);
				
				if(ie == true){
					$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/millerstext.jpg")', "height" : "143px"});
				}
				
				// Fade in text
				$("#rubrik").fadeIn();
				$("#logoButton").fadeIn();
				
				// Set button availability
				$("#b1 img").attr("src", unactive);
				$("#b3 img").attr("src", unactive);
				$("#b2 img").attr("src", active);
				//$("#b4 img").attr("src", unactive);
				
				// Set arrow availability
				$("#prev img").attr("src", p_enabled);
				$("#next img").attr("src", n_enabled);
				
			});
			
			// Fade out text
			$("#rubrik").fadeOut();
			$("#logoButton").fadeOut();
			
			// Animate In
			$("#largeImage").animate({
				marginLeft: "50px"
			}, {
				duration: 1000,
				easing: 'easeOutExpo'
			});
			
		}
	
}
// FUNCTION image2 END



// If image 3 click
function image3(){
	
	// If current not same as click check
	if($("#largeImage").attr("src") != img3){
		
		// Animate out
		$("#largeImage").stop().animate({marginLeft: "-500px"}, function(){
				
			// Change content
			$("#largeImage").attr("src",img3).css({"margin-left" : ""});
			$("#largeImage").unbind("click").css("cursor", "default");
			$("#rubrik").css({"margin-top" : "120px", "margin-left" : "463px"});
			$("#rubrik_h1").text(h1_3).removeClass("case").addClass("p203");
			$("#rubrik_h2").text(h2_3);
			$("#logoButton img").css({"display" : "none"});
			$("#logoButton a").css({"display" : "none"});
			$("#rubrik a").attr("href",link3);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/produktiontext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
			
			// Set button availability
			$("#b1 img").attr("src", unactive);
			$("#b2 img").attr("src", unactive);
			$("#b3 img").attr("src", active);
			//$("#b4 img").attr("src", unactive);
			
			// Set arrow availability
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_disabled);
			
		});
			
		// Fade out text
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "0px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		
	}
	
}
// FUNCTION image3 END

// If image 4 click
/*function image4(){
	
	// If current not same as click check
	if($("#largeImage").attr("src") != img4){
		
		// Animate out
		$("#largeImage").stop().animate({marginLeft: "-500px"}, function(){
				
			// Change content
			$("#largeImage").attr("src",img4).css({"margin-left" : ""});
			$("#largeImage").click(function(){
				window.location=link4;
			}).css( "cursor" , "pointer" );
			$("#rubrik").css({"margin-top" : "120px", "margin-left" : "463px"});
			$("#rubrik_h1").text(h1_4).removeClass("case").addClass("p203");
			$("#rubrik_h2").text(h2_4);
			$("#logoButton img").css({"display" : "none"});
			$("#logoButton a").css({"display" : "none"});
			$("#rubrik a").attr("href",link4);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/produktiontext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
			
			// Set button availability
			$("#b1 img").attr("src", unactive);
			$("#b2 img").attr("src", unactive);
			$("#b3 img").attr("src", unactive);
			//$("#b4 img").attr("src", active);
			
			// Set arrow availability
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_disabled);
			
		});
			
		// Fade out text
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "0px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		
	}
	
}*/
// FUNCTION image4 END



// If next arrow click
function next(){

	if($("#largeImage").attr("src") == img1){
		
		// Animate out
		$("#largeImage").animate({marginLeft: "-500px"}, function(){
			
			// Change content
			$("#largeImage").attr("src",img2).css({"margin-left" : ""});
			$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
			$("#rubrik_h1").text(h1_2).addClass("case").removeClass("p203");
			$("#rubrik_h2").text(h2_2);
			$("#logoButton img").css({"display" : "inline"});
			$("#comimg").attr("src", comimg2);
			$("#logoButton a").css({"display" : "inline"}).attr("href",link2);
			$("#rubrik a").attr("href",link2);
				
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/millerstext.jpg")', "height" : "143px"});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
			
			// Set button activity
			$("#b1 img").attr("src", unactive);
			$("#b3 img").attr("src", unactive);
			$("#b2 img").attr("src", active);
			//$("#b4 img").attr("src", unactive);
				
			// Set arrow activity
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_enabled);
			
		});
			
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate in
		$("#largeImage").animate({
			marginLeft: "50px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		
	} else if($("#largeImage").attr("src") == img2){
		
		// Animate out
		$("#largeImage").animate({marginLeft: "-500px"}, function(){

			// Change content
			$("#largeImage").attr("src",img3).css({"margin-left" : ""});
			$("#rubrik").css({"margin-top" : "120px", "margin-left" : "463px"});
			$("#rubrik_h1").text(h1_3).removeClass("case").addClass("p203");
			$("#rubrik_h2").text(h2_3);
			$("#logoButton img").css({"display" : "none"});
			$("#logoButton a").css({"display" : "none"});
			$("#rubrik a").attr("href",link3);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/produktiontext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
				
			$("#b1 img").attr("src", unactive);
			$("#b2 img").attr("src", unactive);
			$("#b3 img").attr("src", active);
			//$("#b4 img").attr("src", unactive);
				
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_enabled);
		});
			
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "0px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		
	/*} else if($("#largeImage").attr("src") == img3){
		
		// Animate out
		$("#largeImage").animate({marginLeft: "-500px"}, function(){

			// Change content
			$("#largeImage").attr("src",img4).css({"margin-left" : ""});
			$("#rubrik").css({"margin-top" : "120px", "margin-left" : "463px"});
			$("#rubrik_h1").text(h1_4).removeClass("case").addClass("p203");
			$("#rubrik_h2").text(h2_4);
			$("#logoButton img").css({"display" : "none"});
			$("#logoButton a").css({"display" : "none"});
			$("#rubrik a").attr("href",link4);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/produktiontext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
				
			$("#b1 img").attr("src", unactive);
			$("#b2 img").attr("src", unactive);
			$("#b3 img").attr("src", unactive);
			//$("#b4 img").attr("src", active);
				
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_disabled);
		});
			
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "0px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});*/
	}
}
// FUNCTION next END



// Previous arrow
function prev(){

	if($("#largeImage").attr("src") == img2){
		
		// Animate out
			$("#largeImage").animate({marginLeft: "-500px"}, function(){

				// Change content
				$("#largeImage").attr("src",img1).css({"margin-left" : ""});
				$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
				$("#rubrik_h1").text(h1_1).addClass("case").removeClass("p203");
				$("#rubrik_h2").text(h2_1);
				$("#logoButton img").css({"display" : "inline"});
				$("#comimg").attr("src", comimg1);
				$("#logoButton a").css({"display" : "inline"}).attr("href",link1);
				$("#rubrik a").attr("href",link1);
				
				if(ie == true){
					$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/tv4text.jpg")'});
					$("#rubrik a").css({"margin-top" : "0px"});
					$("#comimg").css({"margin-top" : "-20px"});
				}
				
				// Fade in text
				$("#rubrik").fadeIn();
				$("#logoButton").fadeIn();
				
				// Set button activity
				$("#b2 img").attr("src", unactive);
				$("#b3 img").attr("src", unactive);
				$("#b1 img").attr("src", active);
				//$("#b4 img").attr("src", unactive);
				
				// Set arrow activity
				$("#prev img").attr("src", p_disabled);
				$("#next img").attr("src", n_enabled);
				
			});
			
			$("#rubrik").fadeOut();
			$("#logoButton").fadeOut();
			
			// Animate in
			$("#largeImage").animate({
				marginLeft: "50px"
			}, {
				duration: 1000,
				easing: 'easeOutExpo'
			});
		
	} else if($("#largeImage").attr("src") == img3){
		
		// Animate out
		$("#largeImage").animate({marginLeft: "-500px"}, function(){

			// Change content
			$("#largeImage").attr("src",img2).css({"margin-left" : ""});
			$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
			$("#rubrik_h1").text(h1_2).addClass("case").removeClass("p203");
			$("#rubrik_h2").text(h2_2);
			$("#logoButton img").css({"display" : "inline"});
			$("#logoButton a").css({"display" : "inline"}).attr("href",link2);
			$("#rubrik a").attr("href",link2);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/millerstext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
			
			// Set button availability
			$("#b1 img").attr("src", unactive);
			$("#b3 img").attr("src", unactive);
			$("#b2 img").attr("src", active);
			//$("#b4 img").attr("src", unactive);
			
			// Set arrow availability
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_disabled);
			
		});
		
		// Fade out text
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "50px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});
		
	/*} else if($("#largeImage").attr("src") == img4){
		
		// Animate out
		$("#largeImage").animate({marginLeft: "-500px"}, function(){

			// Change content
			$("#largeImage").attr("src",img3).css({"margin-left" : ""});
			$("#rubrik").css({"margin-top" : "55px", "margin-left" : "390px"});
			$("#rubrik_h1").text(h1_3).addClass("case").removeClass("p203");
			$("#rubrik_h2").text(h2_3);
			$("#logoButton img").css({"display" : "inline"});
			$("#logoButton a").css({"display" : "inline"}).attr("href",link3);
			$("#rubrik a").attr("href",link3);
			
			if(ie == true){
				$("#rubrik_h1").css({"background-image" : 'url("/wp-content/themes/p203/images/millerstext.jpg")'});
			}
			
			// Fade in text
			$("#rubrik").fadeIn();
			$("#logoButton").fadeIn();
			
			// Set button availability
			$("#b1 img").attr("src", unactive);
			$("#b3 img").attr("src", active);
			$("#b2 img").attr("src", unactive);
			$("#b4 img").attr("src", unactive);
			
			// Set arrow availability
			$("#prev img").attr("src", p_enabled);
			$("#next img").attr("src", n_enabled);
			
		});
		
		// Fade out text
		$("#rubrik").fadeOut();
		$("#logoButton").fadeOut();
		
		// Animate In
		$("#largeImage").animate({
			marginLeft: "50px"
		}, {
			duration: 1000,
			easing: 'easeOutExpo'
		});*/
		
	}

}
// FUNCTION: prev END
