// JavaScript Document

var current = 0;
var used = [current];
var site = "http://www.kascope.com/";
var images = [site+"src/tent_05.jpg", site+"src/mc35.jpg", site+"src/febrezesport.jpg", site+"src/febrezerefresher.jpg", site+"src/wetjet.jpg", site+"src/drymop.jpg", site+"src/linc.jpg"];
var headlines = ["ORANGE Solar Tent Concept", "MOTOROLA mc35", "P&amp;G Febreze Sport", "P&amp;G Febreze Fabric Refresher", "P&amp;G Swiffer Wet Jet", "P&amp;G Swiffer Dry Mop", "THE GREENER GRASS LINC Phone Concept"];
var copy = ["As part of their sponsorship of the Glastonbury festival, one of Europe&#145;s largest music events, Orange commissioned Kaleidoscope to create a concept for a solar tent that would make the festival more enjoyable for attendees while also making a positive environmental impact.", "Kaleidoscope partnered with Symbol Technology (now Motorola) and their internal design team to create of vision of what this new class of products would be and how it would fit into the larger device eco-system.  Kaleidoscope&#145;s provided all the necessary industrial design assets to communicate and execute the design vision.", "Kaleidoscope was asked to create a line extension that takes Febreze&#39;s &#34;breath of fresh air&#34; into the world of lifestyle sports products. After a series of generative research initiatives, we developed Febreze Sport to help athletes manage odor during transition, and care for delicate high performance apparel.", "P&G needed to improve their Febreeze spray bottles to deliver a more ergonomic and mechanically functional experience that still delivered on the promise of odor free freshness. Leveraging both consumer and product insights, this new ergonomic design requires less handle fatigue, and reduces mechanical issues.", "The re-designed WetJet is sleeker, aesthetically integrated with the existing Swiffer portfolio, yet outperforms its highly successful predecessor. The glossy finish and smooth lines appeal to consumers seeking durability and pleasing aesthetics. Marketable and easier to use, the human factors optimizations set WetJet apart from imitators.", "Kaleidoscope was challenged to create an outstanding cleaning experience that reinforces the &#34;power clean&#34; philosophy and highlights functional improvements at retail. Through collaboration with the P&amp;G team and working closely with the manufacturing vendor, a new aesthetic and ergonomic design was initiated that embodies the key elements of the brand.", "Created for Kaleidoscope&#39;s Greener Grass blog, LINC is a concept that delivers all the connectivity and features you&#39;ve come to expect in a smart phone, but in a modular package that&#39;s easy to update and keeps reusable components in the product cycle."];

$(document).ready(function() {
	/*
	// try to use cookies to control progression
	var kacookie = getCookie("kacookie");
	if (kacookie == "") {
		// generate random number between 0 and images.length
		current = Math.floor(Math.random()*images.length);
		setCookie("kacookie", current, 30);
	}
	else {
		try {
			current = parseInt(kacookie);
			var next =  current + 1;
			if ( next % images.length == 0 ) next = 0;

			setCookie("kacookie", next, 30);
		}
		catch(e){
			current = Math.floor(Math.random()*images.length);
		}
	}
	
	// push the numbers before this into [used]
	for (i = 0; i < current; i++)
	{
		used.push(i);
	}
	loadNewImage();*/
	//setTimeout("beginTextAnimation()", 2500);
	setTimeout("flip2Home()", 3000);
	resizer()
});

function flip2Home(){
	window.location = "http://kascope.com/home";
}

$(window).resize(resizer);

function resizer(){	
	im = $('#backgroundImage');
	imD = im.width() / im.height();
	sc = $(window);
	scD = sc.width() / sc.height();
	
	if(imD > scD){ im.css("height", sc.height()).css("width", "auto"); }
	else{ im.css("width", sc.width()).css("height", "auto"); }
	
	//alert($(this).width()+" "+$(this).height());
}

function refreshPage(){	
	$('#bgOverlay').css("visibility", "visible");
	$('#bgOverlay').animate({ opacity: 1 } , 350 , loadNewImage );
	return false;	
}

function loadNewImage(){
	if(used.length == images.length){
		current = 0;
		used = [0];
	}else{
		current++;
		used.push(current);
	}
	$('#headline').html(headlines[current]);
	$('#copy').html(copy[current]);	
	$('#backgroundImage').attr("src", "");
	$('#backgroundImage').attr("src", images[current]);
	$('#backgroundImage').load(displayWindow);
}

function displayWindow(){
	$('#bgOverlay').animate({ opacity: 0 } , 150 , function(){ $('#bgOverlay').css("visibility", "hidden"); } );
}

function sendBg(){
	/*document['bgf'].bg.value = $('#backgroundImage').attr('src');
	document.forms['bgf'].submit();	*/
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  	c_start=document.cookie.indexOf(c_name + "=");
	 	if (c_start!=-1)
	    {
	    	c_start=c_start + c_name.length+1;
	    	c_end=document.cookie.indexOf(";",c_start);
	    	if (c_end==-1) c_end=document.cookie.length;
	    	return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
var words = ["Experience","Partnership","Design","Function","Strategy","Brand","Approach","Retail","Usability","Delight","Positioning","Aesthetic","Packaging","Vision","Information","Presence","Thought","Communication","Texture","Color","Innovation","Transformation","Perspective","Opportunity","Leadership","Discovery","Influence","Intuition","Narrative","Relevance","Everything"];
var wordCount = 1;
var wordSpeed = 700;

function beginTextAnimation(){
	if(wordCount == 1){
		wordCount++;
		$('#textChanger span').animate({top:"-=65"}, wordSpeed*.7).animate({top:"-=3"}, wordSpeed*.3);
		setTimeout("beginTextAnimation()", wordSpeed);
	}
	if(wordCount<words.length){
		//$('#textChanger').css('opacity',0).html(words[wordCount]).animate({opacity:1},wordSpeed-50);
		wordCount++;
		$('#textChanger span').animate({top:"-=61"}, wordSpeed*.7).animate({top:"-=4"}, wordSpeed*.3);
		tmp=wordSpeed-25;
		wordSpeed = Math.max(150,tmp);
		setTimeout("beginTextAnimation()", wordSpeed);
	}else{
		//$('#textChanger span').css('text-shadow', '#f7901e 0px 0px 1px');
		$('#textChanger span').animate({top:"-=27"}, wordSpeed*.3).animate({top:"-=4"}, wordSpeed*.2);
		//$('#textChanger').css('opacity',0).delay(400).html(words[wordCount]).animate({opacity:1},1500);
	}
}

