﻿// JavaScript Document
window.onload = function() {
	initImage();
	if(marqueetext!=""){populate();}
}
window.onresize = function() {
	//setFooter();
}
var marqueetext = "";

var imageId = 0 //'hometopper1';
var image, image2 //document.getElementById(imageId);
var gCounter = 0;
var gPath = "";
var imageURL1, imageURL2, imageURL3;

var attributes, starttimer;
var polaroid1_down, polaroid2_down, polaroid3_down;
var polaroid1_fade, polaroid2_fade, polaroid3_fade;

function initImage() {
    var ran_unrounded=Math.random()*(gMaxPhotos-1);
    gCounter=Math.round(ran_unrounded); //Start with a random picture
    
    var sbg = YAHOO.util.Dom.getElementsByClassName('cl_10');
    if (sbg.length==1){randomsearch()}
    
    //defaults
	cvi_instant.defaultShadow = 45; //INT 0-100 (% opacity)
	cvi_instant.defaultColor = '#f5eef6'; //STR '#000000'-'#ffffff'
	cvi_instant.defaultNoshade = true; //BOOLEAN
	
	if(imageWidth1 == 0){polaroidlayout();}
	
	
	imageId = 'polaroid1';
	image = document.getElementById(imageId);
	//setOpacity(image, 0);
	imageURL1 = gPath + gImages[gCounter];
	image.src = imageURL1;
	image.style.width = imageWidth1+'px';
	image.style.height = parseInt(imageWidth1*1.167)+'px';
	image.style.marginRight = imageRight1+'px';
	//cvi_instant.add(image, { tilt: "right" });
	cvi_instant.add(image, { tilt: imageTilt1 });
	
	image2 = document.getElementById('polaroid4');
	image2.src = imageURL1;
	image2.style.width = imageWidth1+'px';
	image2.style.height = parseInt(imageWidth1*1.167)+'px';
	image2.style.marginRight = imageRight1+'px';
	cvi_instant.add(image2, { tilt: imageTilt1 });
	
	attributes = { top: { from:-400, to: imageTop1} };
	polaroid1_down = new YAHOO.util.Motion(imageId, attributes, 1.0, YAHOO.util.Easing.easeOutStrong);
	//polaroid1_down.onStart.subscribe(function() { starttimer = setTimeout("polaroid2_down.animate();",500); } );
	
	gCounter = gCounter + 1;
	if (gCounter>=gMaxPhotos) {gCounter = 0;}
	imageId = 'polaroid2';
	image = document.getElementById(imageId);
	imageURL2 = gPath + gImages[gCounter];
	image.src = imageURL2;
	image.style.width = imageWidth2+'px';
	image.style.height = parseInt(imageWidth2*1.167)+'px';
	image.style.marginRight = imageRight2+'px';
	cvi_instant.add(image, { tilt: imageTilt2 });
	
	image2 = document.getElementById('polaroid5');
	image2.src = imageURL2;
	image2.style.width = imageWidth2+'px';
	image2.style.height = parseInt(imageWidth2*1.167)+'px';
	image2.style.marginRight = imageRight2+'px';
	cvi_instant.add(image2, { tilt: imageTilt2 });
	
	attributes = { top: { from:-400, to: imageTop2} };
	polaroid2_down = new YAHOO.util.Motion(imageId, attributes, 1.4, YAHOO.util.Easing.easeOutStrong);
	//polaroid2_down.onStart.subscribe(function() { starttimer = setTimeout("polaroid3_down.animate();",500); } );
	
	gCounter = gCounter + 1;
	if (gCounter>=gMaxPhotos) {gCounter = 0;}
	imageId = 'polaroid3';
	image = document.getElementById(imageId);
	imageURL3 = gPath + gImages[gCounter];
	image.src = imageURL3;
	image.style.width = imageWidth3+'px';
	image.style.height = parseInt(imageWidth3*1.167)+'px';
	image.style.marginRight = imageRight3+'px';
	cvi_instant.add(image, { tilt: imageTilt3 });
	
	image2 = document.getElementById('polaroid6');
	image2.src = imageURL3;
	image2.style.width = imageWidth3+'px';
	image2.style.height = parseInt(imageWidth3*1.167)+'px';
	image2.style.marginRight = imageRight3+'px';
	cvi_instant.add(image2, { tilt: imageTilt3 });
	
	
	//attributes = { top: { from:-300, to: 320}, opacity: {from: 0, to: 1} };
	attributes = { top: { from:-400, to: imageTop3} };
	polaroid3_down = new YAHOO.util.Motion(imageId, attributes, 1.9, YAHOO.util.Easing.easeOutStrong);
	
	
	starttimer = setTimeout("polaroid1_down.animate();",1500);
	starttimer = setTimeout("polaroid2_down.animate();",2000);
	starttimer = setTimeout("polaroid3_down.animate();",2500);
	//polaroid1_d.animate();
	
	
	starttimer = setTimeout("gonext('polaroid1', 'polaroid4', imageTilt1);",4500);
	
	
	//window.setTimeout("fadeIn('"+imageId+"',0)", 150); //go and start fading
}

function gonext(imageId, imageId2, gotilt, gonextfade) {
	document.getElementById(imageId2).style.top = document.getElementById(imageId).style.top;
	document.getElementById(imageId).style.top = '-400px';
	
	cvi_instant.remove(document.getElementById(imageId));
	
	gCounter = gCounter + 1;
	if (gCounter>=gMaxPhotos) {gCounter = 0;}
	image = document.getElementById(imageId);
	imageURL = gPath + gImages[gCounter];
	newImg = new Image();
	newImg.src = imageURL;
	image.src = newImg.src;	
	image.style.width = document.getElementById(imageId2).style.width;
	image.style.height = document.getElementById(imageId2).style.height;
	//cvi_instant.add(image, { tilt: "right" });
	cvi_instant.add(image, { tilt: gotilt });	
	
	attributes = { opacity: {from: 1, to: 0} };
	polaroid1_fade = new YAHOO.util.Motion('polaroid4', attributes, 1.0, YAHOO.util.Easing.easeOutStrong);
	polaroid2_fade = new YAHOO.util.Motion('polaroid5', attributes, 1.0, YAHOO.util.Easing.easeOutStrong);
	polaroid3_fade = new YAHOO.util.Motion('polaroid6', attributes, 1.0, YAHOO.util.Easing.easeOutStrong);
	//starttimer = setTimeout(gonextfade,1800);
	
	//nexttimer = setTimeout("cvi_instant.modify(document.getElementById('polaroid6'),{shadow:1});",170);
	switch(imageId) {
		case 'polaroid1':
			imageURL1 = imageURL;
			//alert(imageURL1);
			starttimer = setTimeout(gonext1,1000);
			break;
		case 'polaroid2':
			imageURL2 = imageURL;
			starttimer = setTimeout(gonext2,1000);
			break;
		case 'polaroid3':
			imageURL3 = imageURL;
			starttimer = setTimeout(gonext3,1000);
			break;
	}

}

function gonext1() {
	document.getElementById('polaroid1').style.top = document.getElementById('polaroid4').style.top;
	cvi_instant.modify(document.getElementById('polaroid4'),{shadow:1});
	polaroid1_fade.animate();
	starttimer = setTimeout("gonext('polaroid2', 'polaroid5', imageTilt2);",3500);
	
	document.getElementById('polaroid6').style.top = '-400px';
	//cvi_instant.modify(document.getElementById('polaroid6'),{shadow:45});
	YAHOO.util.Dom.setStyle("polaroid6", "opacity", 1); 
	
	cvi_instant.remove(document.getElementById('polaroid6'));
	image = document.getElementById('polaroid6');
	image.src = imageURL3;
	image.style.width = document.getElementById('polaroid3').style.width;
	image.style.height = document.getElementById('polaroid3').style.height;
	cvi_instant.add(image, { tilt: imageTilt3 });
}
function gonext2() {
	document.getElementById('polaroid2').style.top = document.getElementById('polaroid5').style.top;
	cvi_instant.modify(document.getElementById('polaroid5'),{shadow:1});
	polaroid2_fade.animate();
	starttimer = setTimeout("gonext('polaroid3', 'polaroid6', imageTilt3);",3500);
	
	document.getElementById('polaroid4').style.top = '-400px';
	//cvi_instant.modify(document.getElementById('polaroid4'),{shadow:45});
	YAHOO.util.Dom.setStyle("polaroid4", "opacity", 1); 
	
	cvi_instant.remove(document.getElementById('polaroid4'));
	image = document.getElementById('polaroid4');
	image.src = imageURL1;
	image.style.width = document.getElementById('polaroid1').style.width;
	image.style.height = document.getElementById('polaroid1').style.height;
	cvi_instant.add(image, { tilt: imageTilt1});
}
function gonext3() {
	document.getElementById('polaroid3').style.top = document.getElementById('polaroid6').style.top;
	cvi_instant.modify(document.getElementById('polaroid6'),{shadow:1});
	polaroid3_fade.animate();
	starttimer = setTimeout("gonext('polaroid1', 'polaroid4', imageTilt1);",3500);
	
	document.getElementById('polaroid5').style.top = '-400px';
	//cvi_instant.modify(document.getElementById('polaroid5'),{shadow:45});
	YAHOO.util.Dom.setStyle("polaroid5", "opacity", 1); 
	
	cvi_instant.remove(document.getElementById('polaroid5'));
	image = document.getElementById('polaroid5');
	image.src = imageURL2;
	image.style.width = document.getElementById('polaroid2').style.width;
	image.style.height = document.getElementById('polaroid2').style.height;
	cvi_instant.add(image, { tilt: imageTilt2 });
}


var imageWidth1 = 0;
var imageWidth2 = 240;
var imageWidth3 = 170;

var imageTop1 = -30;
var imageTop2 = 130;
var imageTop3 = 320;

var imageRight1 = 40;
var imageRight2 = 65;
var imageRight3 = 15;

var imageTilt1 = 'right';
var imageTilt2 = 'left';
var imageTilt3 = 'right';

function polaroidlayout(){
	ran_unrounded=Math.random()*(5);
    rr=Math.round(ran_unrounded);
    //rr=5;
    //window.status = rr;
    
    switch(rr) {
		case 0:
			imageWidth1 = 210;
			imageTop1 = -30;
			imageRight1 = 40;
			imageTilt1 = 'right';
			
			imageWidth2 = 240;
			imageTop2 = 130;
			imageRight2 = 65;
			imageTilt2 = 'left';
			
			imageWidth3 = 170;
			imageTop3 = 320;
			imageRight3 = 15;
			imageTilt3 = 'right';
			break;
		case 1:
			imageWidth1 = 240;
			imageTop1 = 80;
			imageRight1 = 10;
			imageTilt1 = 'right';
			
			imageWidth2 = 210;
			imageTop2 = 270;
			imageRight2 = 85;
			imageTilt2 = 'left';
			
			imageWidth3 = 140;
			imageTop3 = -25;
			imageRight3 = 130;
			imageTilt3 = 'right';
			break;
		case 2:
			imageWidth1 = 163;
			imageTop1 = 330;
			imageRight1 = 140;
			imageTilt1 = 'right';
			
			imageWidth2 = 270;
			imageTop2 = -50;
			imageRight2 = 40;
			imageTilt2 = 'left';
			
			imageWidth3 = 230;
			imageTop3 = 140;
			imageRight3 = 5;
			imageTilt3 = 'right';
			break;
		case 3:
			imageWidth1 = 280;
			imageTop1 = -20;
			imageRight1 = 20;
			imageTilt1 = 'right';
			
			imageWidth2 = 215;
			imageTop2 = 195;
			imageRight2 = 10;
			imageTilt2 = 'left';
			
			imageWidth3 = 20;
			imageTop3 = -500;
			imageRight3 = 5;
			imageTilt3 = 'right';
			break;
		case 4:
			imageWidth1 = 166;
			imageTop1 = -30;
			imageRight1 = 10;
			imageTilt1 = 'right';
			
			imageWidth2 = 270;
			imageTop2 = 100;
			imageRight2 = 10;
			imageTilt2 = 'left';
			
			imageWidth3 = 190;
			imageTop3 = 290;
			imageRight3 = 115;
			imageTilt3 = 'left';
			break;
		case 5:
			imageWidth1 = 280;
			imageTop1 = 170;
			imageRight1 = 20;
			imageTilt1 = 'left';
			
			imageWidth2 = 215;
			imageTop2 = -10;
			imageRight2 = 10;
			imageTilt2 = 'right';
			
			imageWidth3 = 20;
			imageTop3 = -500;
			imageRight3 = 5;
			imageTilt3 = 'right';
			break;
	}
    
}



function randomsearch() {
	var rand = Math.floor( (Math.random() * 6)+1);
	document.getElementById('searchbox').style.backgroundImage = 'url(/assets/templates/default/images/search_bg' + rand + '.gif)';
	
}





var maf_down, maf_up;

function toggleImage(i){
	var obj = document.getElementById(i);
	attributes = { top: { from:-700, to: -10} };
	maf_down = new YAHOO.util.Motion(i, attributes, 1.2, YAHOO.util.Easing.bounceOut);
	attributes = { top: { from:-10, to: -700} };
	maf_up = new YAHOO.util.Motion(i, attributes, 1.0, YAHOO.util.Easing.easeInStrong);
	if(obj){
		if(obj.offsetTop<-200) {
			//obj.style.top='35px';
			maf_down.animate();
		}else {
			//obj.style.top='-700px';
			maf_up.animate();
		}
	}
}



