var j = jQuery.noConflict();

//holds portfolio images
var portImages = Array();

var navPixelAdjust;
var fileName = "projects.xml";
var contentRetrieved;

var navFontSelected;
var navFontSmall;

var tempSize;	

//holds placement of cafe and intro elements
var sectionsTopX = new Array();


//contact info
var bcardInfo = "<div id='bcard'><p>Designer/Developer</p><b>Anthony Baker</b>678.787.5846<br/>anthony at deluxeluxury dot com</div>";

	
//used in loop below
var imageCount=1;
var columnNumber=0;
var totalImages=0;

// number of portfolio columns
var numColumns = 6;
//amoutn of pixels to subtsract from columns width to account for padding and margin space
var numColumnsExtraSpace = 13;

//these variables used in showImages function
//animator interval
var animator;
var showingImages = false;
var currentkey=0;

var logoText = "THE DELUXE LUXURY LOUNGE";

var currentLetter=0;
var logoInterval;

//animation intervals
var generalInterval;
var aniinterval;
var rotatingpart1 = true;



//percentage multiplier for ipod
var m = Array();
//screen size bigger or smaller indice number
var s = 0;
var percents = Array();

//used to move handyman character across the screen
var stopPixel;
var topPixel;

//holds portfolio project ids for use in all functions
var portImageIDs;


//used in walkCharacters()
var randomCharacter = new Array();
var randomSpeed= 90;
randomCharacter[0] = new Array("bouncerright","left",randomSpeed,false);
randomCharacter[1] = new Array("girlright","left",randomSpeed,false);
randomCharacter[2] = new Array("guyright","left",randomSpeed,false);
randomCharacter[3] = new Array("bouncerleft","right",randomSpeed,false);
randomCharacter[4] = new Array("girlleft","right",randomSpeed,false);
randomCharacter[5] = new Array("guyleft","right",randomSpeed,false);
randomCharacter[6] = new Array("policeleft","right",randomSpeed,false);
randomCharacter[7] = new Array("policeright","left",randomSpeed,false);
randomCharacter[8] = new Array("waiterleft","right",randomSpeed,false);
randomCharacter[9] = new Array("waiterright","left",randomSpeed,false);
randomCharacter[10] = new Array("modeltleft","right",randomSpeed,true);
randomCharacter[11] = new Array("modeltright","left",randomSpeed,true);
randomCharacter[12] = new Array("chevyleft","right",randomSpeed,true);
randomCharacter[13] = new Array("chevyright","left",randomSpeed,true);




//display moviing legs on characters
//used with interval called aniinterval
function rotateObjects(object1,object2){


	if(rotatingpart1){
		rotatingpart1=false;
		j('#' + object1).show();
		j('#' + object2).hide();
	}
	else{
		rotatingpart1=true;
		j('#' + object1).hide();
		j('#' + object2).show();
	}
	
}

//copy used for reume showing
//running the funciton with background walkers and resume walker slows down both. 
var rotatingpart1Copy;
function rotateObjectsCopy(object1,object2){

	if(rotatingpart1Copy){
		rotatingpart1Copy=false;
		j('#' + object1).show();
		j('#' + object2).hide();
	}
	else{
		rotatingpart1Copy=true;
		j('#' + object1).hide();
		j('#' + object2).show();
	}
	
}




//gets stop position and top placement position for handyman charcater
function getStopAndTop(){
	//stop pixel in relation to width of handyman
	stopPixel =((j(window).width()/2)-300);
	if(stopPixel<0){
		stopPixel=10;
	}
	
	//gets position in relation to height of sign
	topPixel = interfaceHeight/2-(378/2);
	
	if(topPixel<0){
		topPixel=10;
	}
	
}

//move handy man character to center of screen
function movehandy(){
	
  getStopAndTop();
	
	j('#handyman').css("left",j(document).width());
	j('#handyman_part2').css("left",stopPixel);
	
	j('#handyman').css("top",topPixel + 130);
	j('#handyman_part2').css("top",topPixel);

	j('#handyman').animate({
		left: stopPixel
		}, 3000, 'linear', function(){
			clearInterval(aniinterval);
			aniinterval = null;
      		//j("#test").append(" movehandy" + aniinterval);
      
			j('#handy1').hide();
			j('#handy2').hide();
			j('#handy3').show();
			aniinterval = setInterval(handyClimber, 200);
			});	
	
	clearInterval(aniinterval);
	aniinterval = setInterval(function(){rotateObjects('handy1','handy2')}, 60);		
}

//animates handyman climbing
function handyClimber(){
	j('#handy3').hide();
	j('#climber').show();
	j('#ladder').show();
	clearInterval(aniinterval);
	aniinterval = null;
	
	j('#climber').animate({
		top: 80
		}, 1000, 'linear', function(){
			clearInterval(aniinterval);
			aniinterval = null;
			
			j('#handy4').hide();
			j('#handy5').hide();
			j('#handy6').show();
			handywriting();
			});	
	
	clearInterval(aniinterval);
	aniinterval = setInterval(function(){rotateObjects('handy4','handy5')}, 70);

}

function stopwriting(){
	
	clearInterval(generalInterval);
	generalInterval = null;
	//j("#test").append(" stopwriting" + generalInterval + aniinterval);
	
	j('#climber').show();
	j('#handyarm1').hide();
	j('#handyarm2').hide();
	j("#signtext").text("Now Open");
	j("#signtext").show();
	j('#handy6').hide();
	j('#handy4').show();
	j('#handy5').show();
	
	
	j('#climber').animate({
		top: 240
		}, 1000, 'linear', function(){
			clearInterval(aniinterval);
			aniinterval = null;
			//j("#test").append(" stopwriting climber" + aniinterval);
			
			j('#handy4').hide();
			j('#handy5').hide();
			j('#ladder').hide();
			j('#handy3').show();
			walkOffStage();
			});	
	
	clearInterval(aniinterval);
	aniinterval = null;
	aniinterval = setInterval(function(){rotateObjects('handy4','handy5')}, 70);
	
}

function walkOffStage(){
	
		j('#handy3').hide();
		
		j("#handyman").css("left",stopPixel);
	
		j('#handyman').animate({
		left: 0-(j('#handyman').width()+10)
		}, 3000, 'linear', function(){
			clearInterval(aniinterval);
			aniinterval = null;
			//j("#test").append(" walkOffStage" + aniinterval);
			
			activateButns();
			walkCharacters();
			j("#characterAni").show();
			});	
	
	clearInterval(aniinterval);
	aniinterval = setInterval(function(){rotateObjects('handy1','handy2')}, 60);
	
}

function handywriting(){
	clearInterval(aniinterval);
	aniinterval = setInterval(function(){rotateObjects('handyarm1','handyarm2');}, 100);
	generalInterval = setInterval(stopwriting,2000);
}


function resizeStopper(){	
	var stopper = Math.round(j(window).width()*.08);
	j("#characterAni").css({"width":stopper,"height":stopper,"left":j(window).width()*.02,"top":j(window).height()*.04});
	j("#characterAni img").attr({"width":stopper,"height":stopper});
}


var stopSign = false;

function stopperAction(){
	var stopperSrc = String(j("#characterAni img").attr("src")).match(/butn_stop/);
	var stopperSrc2 = j("#characterAni img").attr("src");
	
	if(!contactOpen && !ipodOpen && !resumeOpen){
		
		if(Boolean(stopperSrc)){
			stopperSrc2 = String(stopperSrc2).replace(/butn_stop/,"butn_go");
			j("#characterAni img").attr("src",stopperSrc2);
			stopWalkers();
			stopSign = true;
			stopClouds();
				
		}
		else{
			stopperSrc2 = String(stopperSrc2).replace(/butn_go/,"butn_stop");
			j("#characterAni img").attr("src",stopperSrc2);
			stopSign=false;
			
			moveClouds();
						
			if(currentFigure>=0){
			 
				restartWalker();
			}
			else{
	
				walkCharacters();
			}
				
		}	
	}
}// end function

function moveElements(){

	navPixelAdjust = j("#nav").width() + 30;
	j('#nav').css("left",j(window).width()-navPixelAdjust);
	
	j("#container").css("width", j(window).width());
	j("#container").css("height", interfaceHeight);
	
	if(j("#cars").css("display")=="block"){
		j("#cars").css("width",j(window).width());
		j("#cars").css("height", interfaceHeight + (interfaceHeight * .1));
	}

	
  	getStopAndTop();
	

	
	j('#handyman').css("left",j(document).width());
	j('#handyman_part2').css("left",stopPixel);
	j('#sidewalk').css("width",j(window).width());
	
	var tempIndice = 0;
	
	if(introHidden){
		tempIndice=1;
	}

	j('#handyman').css("top",topPixel + 130);
	j('#handyman_part2').css("top",topPixel);
	j('#sidewalk').css("top",topPixel + 340);
		
	j('#cityscape').css("top",topPixel -230);

	j('#street').css({"top":j('#cityscape').position().top + j('#cityscape').height() - 5,"height":j(window).height(),"width":j(window).width()});


}


var ipodOpen = false;

function hideIpod(walkerActions){
	
	
	if(j('#ipod').css("display")=="block"){
		ipodOpen = false;
		
		hideProjectInfo();
		
		//j('#ipod').css("display","none");
		
		clearInterval(animator);
		animator = null;
		//j("#test").append(" hideIpod" + animator);
		
		
		j('#ipod').animate({
		top: j(window).height() + 100
		}, 200, 'linear', function(){
			j(this).hide();
	
			moveClouds();
			showingImages=false;
		
			if(walkerActions && !stopSign){
				
				if(currentFigure>=0){
				 
					restartWalker();
				}
				else{
	
					walkCharacters();
				}
				
			}//end if
	
			
		});
		
	}
	
	return false;
}


function showipod(){

	ipodOpen = true;

	resizeipod();
	stopClouds();

	
	if(!figureStopped){
	stopWalkers();
	}
	
	j("#columns div").empty();
	
	j("#portNav").css("display","none");
		
	j('#ipodhand2').css("left",j(window).width());
	j('#ipod').show();
	j('#ipod').css("top",interfaceHeight+50);
	j('#ipod').animate({
		top: percents[3]
		}, 300, 'linear', function(){
			showipodlefthand();
			});
	
	return false;
}

function showipodlefthand(){
		resizeIpodPortfolio();
		j('#ipodhand2').css("left",j(window).width());
		j('#ipodhand2').animate({
		left: percents[4]
		}, 200, 'linear', function(){
			activateButns();
			showProjects(contentRetrieved,null);
		});
}

function resizeipod(){
	
	j('#ipodhand2').css("left",j(window).width());
	
	if(j(window).width()<interfaceHeight){
		s=1;
	}
	else{
		s=0;
	}
	
	m = Array();
	
	m[0] = Array(.95,.95);
	m[1] = Array(.38,.38);
	m[2] = 0;
	m[3] = Array(.15,.25);
	m[4] = Array(.87,.87);
	m[5] = Array(.02,.01);
	m[6] = Array(.633,.633);
	//m[7] = (percents[6]/728) * 544;
	
	var tempPercent = ((j(window).width()*m[6][s])/j("#ipodscreen").width()) * j("#ipodscreen").height();
	m[7] = Array(tempPercent,tempPercent);
	m[8] = Array(.22,.22);
	m[9] = Array(.025,.012);
	
	
	////j("#test").append(j("#ipodscreen").width() + "" + j("#ipodscreen").height());
	
	
	percents[0] = Math.floor(j(window).width()*m[0][s]); //ipod hand
	percents[1] = Math.floor(j(window).width()*m[1][s]); //pointing hand
	percents[2] = m[2]; //ipod hand left
	percents[3] = Math.floor(interfaceHeight*m[3][s]); //ipod hand top
	percents[4] = Math.floor(j(window).width()*m[4][s]); //pointing hand left
	percents[5] = Math.floor(interfaceHeight*m[5][s]) //pointing hand top
	percents[6] = Math.floor(j(window).width()*m[6][s]) //screen width
	percents[7] = Math.floor(m[7][s]) //screen height
	percents[8] = Math.floor(j(window).width()*m[8][s]) //screen left
	percents[9] = Math.floor(interfaceHeight*m[9][s]) //screen top
	

	

	j("#ipod").css("top",percents[3]);
	
	j("#ipod").css("width",j(window).width());
	j("#ipod").css("height",interfaceHeight*1.5);
		
	j("#ipodhand1").css("left",percents[2]);
	j("#ipodhand2").css("left",percents[4]);
	j("#ipodhand2").css("top",percents[5]);
	
	j("#ipodhand1").attr("width", percents[0]);
	j("#ipodhand2").attr("width", percents[1]);
	

	j("#ipodscreen").css("width", percents[6] - 4); // minus border widths
	j("#ipodscreen").css("height", Number(j("#ipodhand1").height() * .62)); // minus border widths
	j("#ipodscreen").css("clip","rect(0px "+ percents[6] + "px " + (j("#ipodscreen").height() + 4) + "px 0px)");
	j("#ipodscreen").css("left",percents[8]);
	j("#ipodscreen").css("top",percents[9]);

	
	var temp = j("#ipodscreen");
	var position = temp.position();
	
	
	j("#ipodclose").attr({'width': j("#ipodscreen").width()*.08 ,'height': j("#ipodscreen").width()*.08});
	
	j("#next").attr({'width': j("#ipodscreen").width()*.05 ,'height': j("#ipodscreen").width()*.05});
	j("#prev").attr({'width': j("#ipodscreen").width()*.05 ,'height': j("#ipodscreen").width()*.05});
	
	j("#ipodclose").css("left",position.left + j("#ipodscreen").width() + (position.left*.1));
	j("#ipodclose").css("top",position.top);
	
	////j("#test").append(j("#ipodhand1").height());
	
	resizeProjectInfo();
		
}


function resizeIpodPortfolio(){
	
	tempSize = Math.floor(j("#ipodscreen").width()/numColumns-numColumnsExtraSpace);
	
	j("#columns div").css("width",tempSize + "px");
	j("#columns div>p").css("width",tempSize + "px");
	j("#columns img").css("width",tempSize + "px");
	j("#columns div>p b").css("width", (tempSize -10) + "px");
	
	j("#columns div").css("width",tempSize + "px");
	j("#columns div>p").css("width",tempSize + "px");
	j("#columns div>p b").css("width", (tempSize -10) + "px");
	
	j("#portNav").css("width",j("#ipodscreen").width() *.95);
	j("#portNav").css("top", j("#ipodscreen").height() - (j("#ipodscreen").height()*.1));
	
	//if project info is displayed 
	//resize project info
	if(j("#projectOverlay").css("display")=="block"){
		resizeProjectInfo();
	}
	
	
}

function portNavHideshow(){

	if(totalPortPages.length>1){
	j("portNav").show();
  }
  else{
  j("portNav").hide();
  }
	
}

function showImages(){
		
	if(Number(currentkey)<Number(totalImages)){
		j("#" + portImageIDs[currentkey]).css({"display":"block"});
		j("#" + portImageIDs[currentkey] + " img").css({"display":"block"});
		currentkey++;
	}
	else if(Number(currentkey)>Number(totalImages)){
		clearInterval(animator);
		animator = null;
		//j("#test").append(" showImages else if " + animator);

		
		showingImages=false;
		portNavHideshow();
		resizeIpodPortfolio();
		
	}
	else{
		clearInterval(animator);
		animator = null;
		//j("#test").append(" showImages else" + animator);
		
		showingImages=false;
		portNavHideshow();
		resizeIpodPortfolio();
	}
	
		
		
}


var dreamsImages;
var dreamsXML;

function processDreams(xml,status,xmlHttp){
	
	dreamsXML = j(xml);
	
	dreamsImages = new Array();
	
	j(xml).find("graphic").each(function()
	{		
			dreamsImages.push(j(this).text());
	});
	
	posterDream();

	u1XmlLoader(fileName,assignXMl);
	//walkCharacters();
	
}

var news;

function processNews(xml,status,xmlHttp){
	
	news = new Array();
	
	j(xml).find("item").each(function()
	{		
			news.push(new Array(j(this).find("title").text(),j(this).find("link").text(),j(this).find("pubDate").text()));
	});
	
}


function posterDream(){
	
	var ranDream = Math.round(Math.random()*Number(dreamsImages.length-1));
	currentDream = dreamsImages[ranDream];

	var tempDream = String(currentDream).replace(/width=300/,"width=" + 600);
	j("#loungesign").css("background-image","url(" + tempDream + ")");
	j("#loungesign").css("background-position","center -" +  (j("#loungesign").height()*.15) + "px");
	
	
	var newwidth = j(window).width()*.9;
	var newheight = (newwidth/j("#lounge").width())*j("#lounge").height();
	
	j("#loungesign").css("width",j("#lounge").width() * .42);
	j("#loungesign").css("height",j("#lounge").height() * .45);
	j("#loungesign").css("top",j("#lounge").height() * .45);
	j("#loungesign").css("left",j("#lounge").width() * .05);
	
	j("#loungesign").css("display","block");
	
}


//assigns xml text 
function assignXMl(xml,status,xmlHttp){
	contentRetrieved = j(xml);
	calculatePages();
	u1XmlLoader("weather.xml",showWeather);
}


function showWeather(xml){
	
	//gets current weather as text
	var tempWeather = String(j(xml).find("title:eq(2)").text());
	
	//j("#test").text(j(xml).find("title:eq(2)").text());

	var weatherPattern= new Array();
	weatherPattern[0] = new Array(/dreary|overcast|fog|cloud/i,"clouds","<img src='images/clouds.gif' width='1200' height='156' id='weather_clouds'/>");
	weatherPattern[1] = new Array(/storm|rain|shower/i,"rain","<div id='weather_rain'></div>");
	weatherPattern[2] = new Array(/sun|partly|clear/i,"sun","<img src='images/sun.gif' width='260' height='260' id='weather_sun'/>");
	
		
	for(var i=0;i<weatherPattern.length;i++){
		
		if(tempWeather.match(weatherPattern[i][0])){
			
			switch(i){
				case 0:
					//clouds
					j("#weatherArea").html(weatherPattern[0][2]);
					moveClouds();
					break;
				
				case 1:
					//rain with clouds
					j("#weatherArea").html(weatherPattern[0][2] + weatherPattern[1][2]);
					j("#weather_rain").css({"height":j("#weatherArea").height() + "px","width":j(window).width() + "px"});
					moveClouds();
					break;
				
				default:
					// if partly sunny
					if(tempWeather.match(/partly|cloudy/i)){
							j("#weatherArea").html(weatherPattern[0][2] + weatherPattern[2][2]);
							moveClouds();
							startSunAni();
					}
					//sunny
					else{
						j("#weatherArea").html(weatherPattern[2][2]);
						startSunAni();
					}
					
					break;
				
			}// end switch

		}// end if
	}// end for
	
	resizeWeather();
}

var cloudsOnStage = false;

function moveClouds(){
		
if(j("#weather_clouds").length>0){		

	if(!contactOpen && !ipodOpen && !resumeOpen && !stopSign){		
	
		if(!cloudsOnStage){
			j("#weather_clouds").css("left", Number(j(window).width()) + 20);
			cloudsOnStage=true;
		}
		
		j("#weather_clouds").animate({
			left: 0-Number(j("#weather_clouds").width())
		  }, 40000, 'linear', function(){
			cloudsOnStage=false;
			moveClouds();
		});
		
	}
}
	//j("#test").text(j("#weatherArea").html());
}


function stopClouds(){
	if(j("#weather_clouds").length>0){
	j("#weather_clouds").stop();
	}
}

function startSunAni(){
	
}



function xmlError(jqXHR, textStatus, errorThrown){
	//j("#test").append(jqXHR + "<br/>" + textStatus + "<br/>" + errorThrown);
}

//loads xml file and starts parser
function u1XmlLoader(xmlFile,xmlFunction){
	 j.ajax({
    	url: xmlFile,
		//processData: false,
		//crossDomain: true,
		//isLocal: true,
    	dataType: "xml",
		isLocal: true,
		error: xmlError,
    	success: xmlFunction
	});
}

var totalPortPages = Array();
var currentPage = 1;


function calculatePages(){
	//calculate number of pages to display
	j(contentRetrieved).find("project").each(function()
	{		
		if(j(this).attr("page")!=j(this).prev().attr("page")){
			totalPortPages.push(j(this).attr("page"));
		}	
	});
	

}

function showProjects(xml,status,page)
{
	
	//empties all the columns
	j("#columns div").empty();
	j("#portNav").show();
	
	showingImages=true;
	var i=1;
	var totalProjects = 0;
	var breakCounter=0;
	currentPage = page;
	
	if(!page){
		currentPage=1;	
	}
	
	
	//used in loop below
	imageCount=1;
	columnNumber=0;
	totalImages=0;
	
	portImageIDs = new Array();

	
	//find every project with current page number
	j(xml).find("project[page='" + currentPage +  "']").each(function()
	{
		totalProjects++;
		portImageIDs.push(String(j(this).attr("id")));
	});
	
	//j("#test").empty();
	
	j(xml).find("project[page='" + currentPage +  "']").each(function()
	{
				
		if(j(this).find("projTitle").length>0){	

			  var temp = String(j(this).find("graphic").text()).replace(/width=300/i,"width=" + tempSize + "&amp;cropratio=3:3");
			  //portImages.push(temp);
			
			
			//var image1 = j("<p id='image" + totalImages + "'><img src='" + temp + "'/><b>" + j(this).find("projTitle").text() + "</b><a href='http://" + j(this).find("projUrl").text() + "'>View Project</a></p>");
			  var image1 = j("<p id=\"" + String(j(this).attr("id")) + "\"><a href='javascript: return false;'><img src='" + temp + "' alt='" + j(this).find("projTitle").text() +  "'/></a></p>");		 

			// push image drawing to next column
						
			  if(imageCount>Math.round(totalProjects/numColumns) && Math.round(totalProjects/numColumns)!=0){
				columnNumber++;
				  imageCount=1;
			  }
			  
			  // starts redrawing in column 0
			  //if current column greater than numCOlumns defined to have
			  if(columnNumber>numColumns-1){
				  columnNumber=0;
			  }
			  
				//appends project to column
			  j("#columns div:eq(" + columnNumber + ")").append(image1);

			  // used to guage column to display in
			  imageCount++;
			  //used in showImages funciton
			  totalImages++;
			  
		}
		

		
		j("#columns p img").bind("mouseover",function(){
			j(this).fadeTo(0,.5);
			j("#portNav").html(j(this).attr("alt"));
		});
		
		
		j("#columns p img").bind("mouseout",function(){
				j(this).fadeTo(0,1);	
				j("#portNav").empty();
		});
		
		
		j("#columns p").bind("click",function(){
				showProjectInfo(j(this).attr("id"));
				return false;
		});

		resizeIpodPortfolio();
	
	
  	});
	

	//hides all b elements in portfolio
	//j("#columns p>b").fadeTo(0,0);
	j("#columns p>b").css("display","none");
	
	//resets currentkey variable used in animator interval
	currentkey=0;
	animator = setInterval(showImages,100);

	
}


function changePages(direction){
	
	switch(direction){
		case 'prev':
			currentPage--;
			if(currentPage<1){
				currentPage = totalPortPages[totalPortPages.length-1];
			}
			
		break;
		
		default:
			currentPage = currentPage+1;

			if(currentPage>totalPortPages.length){
			currentPage = 1;
			}
						
		break;
	}// end switch
	
	showProjects(contentRetrieved,null,currentPage);
	
	return false;
	
}//changePages end


function resizeProjectInfo(){
		//resize project info overlay screen
	var tempLengths = Array(j("#ipodscreen").width(),j("#ipodscreen").height());
	j("#projectOverlay").css('width',tempLengths[0] - (tempLengths[0]*.01));
	j("#projectOverlay").css('height',tempLengths[1] -(tempLengths[1]*.04));
	
	if(j("#projectImage img").attr("height")!=0){
		
		var temp1 = getProportion(tempLengths[0],j("#projectImage img").attr("width"),j("#projectImage img").attr("height"));

	
		j("#projectImage img").css("width",tempLengths[0]);
		j("#projectImage img").attr("width",tempLengths[0]);	
		
		//j("#projectImage img").css("height",temp1);
		//j("#projectImage img").attr("height",temp1);
		
		
	}
	
	j("#closer").attr({'width': tempLengths[0]*.05,'height': tempLengths[0]*.05});
	
	
	j("#projectDataText").css("top",j("#ipodscreen").height()*.4);
	j("#projectDataText").css("margin-left",j("#ipodscreen").width()*.3);
	j("#projectDataText").css("width",j("#ipodscreen").width() *.6);
	
	j("#projectDataBackgrnd").css("top",j("#ipodscreen").height()*.4);
	j("#projectDataBackgrnd").css("height",j("#projectDataText").height() + 60);
	j("#projectDataBackgrnd").css("width",j("#projectDataText").width());
	j("#projectDataBackgrnd").css("width",j("#ipodscreen").width());
	j("#projectDataBackgrnd").css("margin-left",j("#ipodscreen").width()*.3);
	
	
	j("#projectData").css("height",j("#ipodscreen").height()-30);
	
}


function sizeProjectImage(curWidth,curHeight){
	
	var tempClean1 = String(curWidth).replace(/px/,"");
	var tempClean2 = String(curHeight).replace(/px/,"");

	var tempHeight = getProportion(j("#ipodscreen").width(),tempClean1,tempClean2);
	
	return tempHeight;
}


var testerInt;

function traceIntervals(){
	j("#test").append(j("#loadMessage").text() + loadChecker + "<br/>");
	if(Number(j("#test").text().length)>500){
		j("#test").empty()
	}
}

//		testerInt = setInterval(traceIntervals,1000)



function checkProjectImage(){
	
	if(Number(j("#loadMessage").text().length)<=0){
		createLoadMessage();
		loadMessageText("LOADING<br/>-");
		
		
		j("#closer").css("display","none");
	}
	
	if(j("#projectImage img").attr('complete')){
	
		clearInterval(loadChecker);
		loadChecker = null;
			
		j("#loadMessage").hide();
		j("#loadMessage").empty();
		
		j("#projectImage img").css("visibility","visible");
		j("#closer").css("display","block");
		
		j("#projectDataText").show();
		j("#projectDataBackgrnd").show();
		j("#closer").show();	
	
		
		j("#projectImage img").css("width",j("#ipodscreen").width());
		
		//j("#projectImage img").css("height",sizeProjectImage(j("#ipodscreen").width(),j("#projectImage img").attr("height")));
		

	}
	else{	

		
		if(Number(j("#loadMessage").text().length)>30)
		{
			loadMessageText("LOADING<br/>-");
		}
		loadMessageText(j("#loadMessage").html() + "-");
	}

}



function hideProjectInfo(){

	j("#projectOverlay").hide();
	j("#projectData").hide();	
	j("#projectDataText").hide();
	j("#projectDataBackgrnd").hide();
	j("#closer").hide();	
	j("#projectImage").empty();
	j("#projectDataText").empty();
	
	j("#columns").css("visibility","visible");
	j("#portTitle").css("visibility","visible");
	//portNavHideshow();
	j("#output").css("padding-left","10px");
	
	return false;
}

function showProjectInfo(selectedID){
	
	var tempXML = j(contentRetrieved).find("project[id='" + selectedID +  "']");
	

	// + "&amp;cropratio=3:3"
	var projImgSize = Array(j("#ipodscreen").width() + 10,j("#ipodscreen").height());
	var tempImage = String(j(tempXML).find("graphic").text()).replace(/width=300/i,"width=" + projImgSize[0] + "cropratio=" + projImgSize[0] + ":" + projImgSize[1]);
	
	//j("#projectData").html("<img src='" + tempImage + "'/>" + j(tempXML).find("projTitle").text() + "<br/>" + j(tempXML).find("projDescrip").text() + "<br/>" + j(tempXML).find("projUrl").text());
	
	j("#projectDataText").html("<span>" + j(tempXML).find("projTitle").text() + "</span>" + j(tempXML).find("projDescrip").text());
	
	
	if(Boolean(j(tempXML).find("projUrl").text())){
	j("#projectDataText").append("<a href='http://" + j(tempXML).find("projUrl").text() + "' target='new'>" + j(tempXML).find("projUrl").text() + "</a>");
	}
	
	j("#projectImage").html("<img src='"  +  tempImage + "'/>");
	//j("#projectDataBackgrnd").fadeTo(100,.9);

	clearInterval(loadChecker);
	loadChecker = setInterval(checkProjectImage,500);

  	j("#projectOverlay").show();
	j("#projectData").show();	
	j("#projectDataBackgrnd").show();

	resizeProjectInfo();

	j("#columns").css("visibility","hidden");
	j("#portTitle").css("visibility","hidden");
	portNavHideshow();
	
	j("#output").css("padding-left","0px");

}


// not going to use this function
function resizeAndPlaceIntro(){
	j("#sign").css("height",j("#lounge").height());
	j("#sign").css("width",(j("#lounge").height()/378)*302);
}


function resizeWeather(){
	
	var cloudHeight = Math.round(j("#lounge").height()*.4);
	var cloudWidth = getProportion(cloudHeight,156,1200);
	
	var sunWidth = Math.round(j("#lounge").height()*.4);
	
	j("#weather_clouds").attr({"height":cloudHeight,"width":cloudWidth});
	j("#weather_clouds").css({"top":j(window).height()*.1});
	j("#weather_sun").attr({"height":sunWidth,"width":sunWidth});
	j("#weather_sun").css({"top":j(window).height()*.05,"left":j(window).height()*.2});
	
	j("#weatherArea").css({"height":j("#street").position().top + "px","width":j(window).width() + "px"});
	j("#weather_rain").css({"height":j("#weatherArea").height(),"width":j(window).width()});

}

function resizelounge(){
	
	/*
	if(j(window).width()<interfaceHeight){
		j('#loungearea').css("visibility","hidden");
	}
	else{
		j('#loungearea').css("visibility","visible");
	}
	*/
	
	var sidewalktop = String(j("#sidewalk").css("top"));
	sidewalktop = sidewalktop.replace(/px/,"");
	
	var newwidth = j(window).width()*.9;
	var newheight = (newwidth/j("#lounge").width())*j("#lounge").height();
	
	
	if(!introHidden){
		if(newwidth<1031){
			j('#loungearea').css("left",Math.floor(j(window).width()*.05));
			j('#loungearea').css("top",sidewalktop - (newheight-20));
			
			j("#loungesign").css("width",newwidth * .42);
			j("#loungesign").css("height",newheight * .45);
			j("#loungesign").css("top",newheight * .45);
			j("#loungesign").css("left",newwidth * .05);
			
			j("#lounge").css("width",newwidth);
			j("#lounge").css("height",newheight);
			
		}
		else{
			j('#loungearea').css("left",Math.floor(j(window).width()*.11));
			j('#loungearea').css("top",sidewalktop - (j("#lounge").height()-20));
		}
		
		j("#scene").show();
		j("#scene").css("height",j("#lounge").height()*.4);
		j("#scene").css("width",j("#lounge").width()*.1);
		j("#scene").css("top",j("#loungearea").position().top + j("#lounge").height()*.55);
		j("#scene").css("left",j("#loungearea").position().left + j("#lounge").width()*.61);
		j("#scene").empty();
	}
	else{
		j('#loungearea').css("top",-700);
	}
	
	
	// not using for the moment
	//resizeAndPlaceIntro();
}




function resizeFigures(){
	
	//object's height used to calculate size of figures
	var tempSizer;
	
	//gets top position of sidewalk for figure top placement
	var sidewalkTop;
	
	if(!introHidden){
		tempSizer = j("#lounge").height();
		sidewalkTop = j("#sidewalk").position().top;
	}
	else{
		tempSizer = j("#windowmiddle").height();
		sidewalkTop = j("#sidewalk").position().top + (j("#sidewalk").position().top*.1);
	}

	
	var figuresValues = Array();
	//height of bouncer
	figuresValues[0]= Math.floor(tempSizer*.85);
	//widthof bouncer
	figuresValues[1]= Math.floor((figuresValues[0]/602) * 387);
	
	//height o girl
	figuresValues[2]= Math.floor(tempSizer*.80);
	//width of girl
	figuresValues[3]= Math.floor((figuresValues[2]/578) * 162);
	
	//height of guy
	figuresValues[4]= Math.floor(tempSizer*.60);
	//width of guy
	figuresValues[5]= Math.floor((figuresValues[4]/458) * 189);

	//height of police
	figuresValues[6]= Math.floor(tempSizer*.85);
	//widthof police
	figuresValues[7]= Math.floor((figuresValues[6]/602) * 350);
	
	//height of car
	figuresValues[8]= Math.floor(tempSizer);
	//widthof car
	figuresValues[9]= Math.floor((figuresValues[8]/500) * 910);
	
	//height of car
	figuresValues[10]= Math.floor(tempSizer*.80);
	//widthof car
	figuresValues[11]= Math.floor((figuresValues[10]/375) * 1720);
	
	
	//height of waiter
	figuresValues[12]= Math.floor(tempSizer*.85);
	//width of waiter
	figuresValues[13]= Math.floor((figuresValues[6]/667) * 340);
	
		
	var figureTopPercents = new Array(.80,.80,.80);
	
	//--- figures going left
	
	//sets heights and width of bouncer
	j("#bouncerright1").css("height",figuresValues[0]);
	j("#bouncerright1").css("width",figuresValues[1]);
	j("#bouncerright2").css("height",figuresValues[0]);
	j("#bouncerright2").css("width",figuresValues[1]);
	j("#bouncerright").css("top",Math.floor(sidewalkTop-figuresValues[0]*figureTopPercents[0]));
	j("#bouncerright").css("left",j(window).width() + figuresValues[1]);
	j("#bouncerright").css("height",figuresValues[0]);
	j("#bouncerright").css("width",figuresValues[1]);
	
	
	
	//sets heights and width of girl
	j("#girlright1").css("height",figuresValues[2]);
	j("#girlright1").css("width",figuresValues[3]);
	j("#girlright2").css("height",figuresValues[2]);
	j("#girlright2").css("width",figuresValues[3]);
	j("#girlright").css("top",Math.floor(sidewalkTop-figuresValues[2]*figureTopPercents[1]));
	j("#girlright").css("left",j(window).width() + figuresValues[3]);
	j("#girlright").css("height",figuresValues[2]);
	j("#girlright").css("width",figuresValues[3]);
	
	
	//sets heights and width of guy
	j("#guyright1").css("height",figuresValues[4]);
	j("#guyright1").css("width",figuresValues[5]);
	j("#guyright2").css("height",figuresValues[4]);
	j("#guyright2").css("width",figuresValues[5]);
	j("#guyright").css("top",Math.floor(sidewalkTop-figuresValues[4]*figureTopPercents[2]));
	j("#guyright").css("left",j(window).width() + figuresValues[5]);
	j("#guyright").css("height",figuresValues[4]);
	j("#guyright").css("width",figuresValues[5]);
	
	
	//sets heights and width of police
	j("#policeright1").css("height",figuresValues[6]);
	j("#policeright1").css("width",figuresValues[7]);
	j("#policeright2").css("height",figuresValues[6]);
	j("#policeright2").css("width",figuresValues[7]);
	j("#policeright").css("top",Math.floor(sidewalkTop-figuresValues[6]*figureTopPercents[2]));
	j("#policeright").css("left",j(window).width() + figuresValues[7]);
	j("#policeright").css("height",figuresValues[6]);
	j("#policeright").css("width",figuresValues[7]);
	
	
	
	//sets heights and width of waiter
	j("#waiterright1").css("height",figuresValues[[12]]);
	j("#waiterright1").css("width",figuresValues[[13]]);
	j("#waiterright2").css("height",figuresValues[[12]]);
	j("#waiterright2").css("width",figuresValues[[13]]);
	j("#waiterright").css("top",Math.floor(sidewalkTop-figuresValues[[12]]*figureTopPercents[2]));
	j("#waiterright").css("left",j(window).width() + figuresValues[[13]]);
	j("#waiterright").css("height",figuresValues[[12]]);
	j("#waiterright").css("width",figuresValues[[13]]);
	
	
	
	//figures going right
	
	//sets heights and width of bouncer
	j("#bouncerleft1").css("height",figuresValues[0]);
	j("#bouncerleft1").css("width",figuresValues[1]);
	j("#bouncerleft2").css("height",figuresValues[0]);
	j("#bouncerleft2").css("width",figuresValues[1]);
	j("#bouncerleft").css("top",Math.floor(sidewalkTop-figuresValues[0]*figureTopPercents[0]));
	j("#bouncerleft").css("left",0 - figuresValues[1]);
	j("#bouncerleft").css("height",figuresValues[0]);
	j("#bouncerleft").css("width",figuresValues[1]);
	
	
	//sets heights and width of girl
	j("#girlleft1").css("height",figuresValues[2]);
	j("#girlleft1").css("width",figuresValues[3]);
	j("#girlleft2").css("height",figuresValues[2]);
	j("#girlleft2").css("width",figuresValues[3]);
	j("#girlleft").css("top",Math.floor(sidewalkTop-figuresValues[2]*figureTopPercents[1]));
	j("#girlleft").css("left",0 - figuresValues[3]);
	j("#girlleft").css("height",figuresValues[2]);
	j("#girlleft").css("width",figuresValues[3]);
	
	
	//sets heights and width of guy
	j("#guyleft1").css("height",figuresValues[4]);
	j("#guyleft1").css("width",figuresValues[5]);
	j("#guyleft2").css("height",figuresValues[4]);
	j("#guyleft2").css("width",figuresValues[5]);
	j("#guyleft").css("top",Math.floor(sidewalkTop-figuresValues[4]*figureTopPercents[2]));
	j("#guyleft").css("left",0 - figuresValues[5]);
	
	j("#guyleft").css("height",figuresValues[4]);
	j("#guyleft").css("width",figuresValues[5]);
	
	
	//sets heights and width of police
	j("#policeleft1").css("height",figuresValues[6]);
	j("#policeleft1").css("width",figuresValues[7]);
	j("#policeleft2").css("height",figuresValues[6]);
	j("#policeleft2").css("width",figuresValues[7]);
	j("#policeleft").css("top",Math.floor(sidewalkTop-figuresValues[6]*figureTopPercents[2]));
	j("#policeleft").css("left",j(window).width() + figuresValues[7]);
	j("#policeleft").css("height",figuresValues[6]);
	j("#policeleft").css("width",figuresValues[7]);
	
	//sets heights and width of waiter
	j("#waiterleft1").css("height",figuresValues[[12]]);
	j("#waiterleft1").css("width",figuresValues[[13]]);
	j("#waiterleft2").css("height",figuresValues[[12]]);
	j("#waiterleft2").css("width",figuresValues[[13]]);
	j("#waiterleft").css("top",Math.floor(sidewalkTop-figuresValues[[12]]*figureTopPercents[2]));
	j("#waiterleft").css("left",j(window).width() + figuresValues[[13]]);
	j("#waiterleft").css("height",figuresValues[[12]]);
	j("#waiterleft").css("width",figuresValues[[13]]);
	
	
	//sets heights and width of model t
	j("#modeltleft").css("top",Math.floor(sidewalkTop-figuresValues[8]*.2));
	j("#modeltleft").css("left",j(window).width() + figuresValues[9]);
	j("#modeltleft").css("height",figuresValues[8]);
	j("#modeltleft").css("width",figuresValues[9]);
	j("#modeltleft").attr("height",figuresValues[8]);
	j("#modeltleft").attr("width",figuresValues[9]);
	
	
	//sets heights and width of model t
	j("#modeltright").css("top",Math.floor(sidewalkTop-figuresValues[8]*.2));
	j("#modeltright").css("right",j(window).width() + figuresValues[9]);
	j("#modeltright").css("height",figuresValues[8]);
	j("#modeltright").css("width",figuresValues[9]);
	j("#modeltright").attr("height",figuresValues[8]);
	j("#modeltright").attr("width",figuresValues[9]);
	
	
	//sets heights and width of model t
	j("#chevyleft").css("top",Math.floor(sidewalkTop-figuresValues[10]*.2));
	j("#chevyleft").css("left",j(window).width() + figuresValues[11]);
	j("#chevyleft").css("height",figuresValues[10]);
	j("#chevyleft").css("width",figuresValues[11]);
	j("#chevyleft").attr("height",figuresValues[10]);
	j("#chevyleft").attr("width",figuresValues[11]);
	
	
	//sets heights and width of model t
	j("#chevyright").css("top",Math.floor(sidewalkTop-figuresValues[10]*.2));
	j("#chevyright").css("right",j(window).width() + figuresValues[11]);
	j("#chevyright").css("height",figuresValues[10]);
	j("#chevyright").css("width",figuresValues[11]);
	j("#chevyright").attr("height",figuresValues[10]);
	j("#chevyright").attr("width",figuresValues[11]);
	
	
	 
	if(currentFigure>=0){
		j("#" + randomCharacter[currentFigure][0]).css("left",currentFigurePosition);
	}
}


//used in moveCharacters()
var figureInterval;

function moveCharacters(charID,direction,walkSpeed,objectIsCar){
		
	//local variable
	var endPoint;
	var defaultSpeed = 4000;
	var animationSpeed;
	var aniPercent;
	
	//right to left
	if(direction=="left"){
		if(!figureStopped){
			j("#" + charID).css("left",j(window).width() + j("#" + charID).width());
			animationSpeed=defaultSpeed;
		}
		else{
			animationSpeed=defaultSpeed;
			aniPercent = Number("." + Math.round((j("#" + charID).position().left/j(window).width() * 100)));
			
			if(isNaN(aniPercent)){
				aniPercent=.05;
			}
			
			animationSpeed = defaultSpeed*aniPercent;
		}
		endPoint = 0 - (j("#" + charID).width()*2);
	}
	else{//left to right
		if(!figureStopped){
			j("#" + charID).css("left",0 - j("#" + charID).width());
			animationSpeed=defaultSpeed;
		}
		else{
			animationSpeed=defaultSpeed;
			aniPercent = Number("." + Math.round(100 - (j("#" + charID).position().left/j(window).width() * 100)));
			if(isNaN(aniPercent)){
				aniPercent=.05;
			}			
			animationSpeed = defaultSpeed*aniPercent;
		}
		endPoint = j(window).width() + (j("#" + charID).width()*2);
	}
		
	var tempBubble = j("#bubble").length;
                       
	if(tempBubble==0 && !objectIsCar){
		showSpeechBubble();
	}
	
	j("#" + charID).animate({
		left: endPoint
		}, animationSpeed, 'linear', function(){
			clearInterval(figureInterval);
			figureInterval = null;
			//j("#test").empty();
      		//j("#test").append(" moveCharacters" + figureInterval);
      
	  		 j("#bubble").unbind('click');
			 j("#bubble").remove();

			
			walkCharacters(currentFigure);
			});	
	
	//if object is a car
	//does not rotate legs
	if(!objectIsCar){
		clearInterval(figureInterval);
		figureInterval = setInterval(function(){rotateObjects(charID + "1",charID + "2")}, Number(walkSpeed));
	}
	figureStopped=false;
	

	
}

var currentFigure;
var currentDream;
var figureStopped = false;



//starting this function but may not be using
function getProportion(reproVal,origVal1,origVal2){
	
	/*
	Proportion Calculator
	
	(Repro width / original width) * original height = repro height;
	(original width / Repro width) * 100 = enlargement percentage
	*/
	
	var newproportion = Math.floor((reproVal/origVal1) * origVal2);
	return newproportion;
}

var currentFigurePosition;

//used when ipod appears
function stopWalkers(){
	if(currentFigure>=0 && !figureStopped){
		figureStopped=true;
		clearInterval(figureInterval);
		figureInterval = null;
		//j("#test").append(" stopWalkers" + figureInterval);
		
		j("#" + randomCharacter[currentFigure][0]).stop();
		currentFigurePosition = j("#" + randomCharacter[currentFigure][0]).position().left;
		
		clearInterval(figureInterval);
	
	}
	
}

var bubblesHidden = true;

function showSpeechBubble(){
			j("#" + randomCharacter[currentFigure][0]).append("<a href='' id='bubble'><div id='dream'></div><img src='images/speech_bubble1.gif' width='330' height='266' id='bubbleback' alt='Speech Bubble'/></a>");
			j("#bubble").bind('click',function(){showPopArt(); return false;});
			resizeSpeechBubble();
}

function resizePopart(){
	
	var imageHeight = Math.round(j(window).height() *.7);
	
	if(j("#popart").length>0){
		
		
		//var newImageWidth = getProportion(imageHeight,j("#popimage").width(),j("#popimage").height());
		//j("#popimage").attr({"height":imageHeight,"width":newImageWidth});
		
		j("#popart").css({
						 "top":Math.round(j(window).height()/2) - j("#popimage").height()/2, 
						 "left":Math.round(j(window).width()/2 - j("#popimage").width()/2),
						 //"width":newImageWidth,
						 //"height":j("#popimage").height(),
						 "padding":"0px 0px 20px 0px",
						 "visibility":"visible"
						 });
	}//end if
}//resizePopart

function checkPopImage(){
		
	if(Number(j("#loadMessage").text().length)<=0){
		createLoadMessage();
		loadMessageText("LOADING<br/>-");
	
	}
	
	if(j("#popimage").attr('complete')){

		clearInterval(loadChecker);
		loadChecker=null;
		
		j("#loadMessage").hide();
		j("#loadMessage").empty();
		j("#popart").css("visibility","visible");
	
	}
	else{	
		if(Number(j("#loadMessage").text().length)>30)
		{
			loadMessageText("LOADING<br/>-");
		}
		
		loadMessageText(j("#loadMessage").html() + "-");
	}

}




function showPopArt(){
	
	var tempDream = String(j("#dream").css("background-image")).replace(/url\(|"|\)/gm,"");
	//tempDream = tempDream.replace(/(width\=)[0-9]{3,4}/,"$1" + Math.round(j(window).width() *.5));
	
	var imageHeight = Math.round(j(window).height() *.7);
	tempDream = tempDream.replace(/(width\=)[0-9]{3,4}/,"height=" + imageHeight);

	if(j("#popart").length>0){
		j("#popart").remove();
	}
	
	j("body").append("<div id='popart'><a href='' id='popclose'><img src='images/butn_close.png' width='30' height='30'></a><img src='" + tempDream + "' height='" + imageHeight + "' id='popimage'/></div>");
	
	//<div id='popartback'></div>
	
	if(j("#popart").length>0){	
		j("#popimage").load(
			function(){
				
				var popWidth = j(this).width();
				var popHeight = j(this).height();
								
				if(Number(j(this).width())>Number(j(window).width())){
					popWidth = j(window).width() *.7
					popHeight = getProportion(popWidth,j(this).width(),j(this).height())
				}
				
				var popTop = Math.round(j(window).height()/2) - popHeight/2;
				
				
				
				j("#popart").css({
								 "top":0-popHeight + 20, 
								"padding":"0px 0px 20px 0px",
								"left":Math.round(j(window).width()/2 - popWidth/2),
								"width":popWidth + "px",
								"height":popHeight + "px",
								"display":"block"
								});
				/*
				j("#popartback").css({
								"top":"0px",
								"left":"0px",
								"width":popWidth + "px",
								"height":popHeight + "px",
								"display":"block"
								});
				*/
				j("#popimage").attr({"width":popWidth,"height":popHeight});
				j("#popimage").css({"visibility":"visible"});
				
				j("#popclose").bind("click",function(){
								j("#popart").fadeOut(100, function(){j(this).remove();});
								return false;
								});
				
				j("#popart").animate({
									 top: popTop
									 },250,'linear');
				
			}
		);
	}
	
	clearInterval(loadChecker);
	loadChecker = setInterval(checkPopImage,100);
	
	return false;
}


function resizeSpeechBubble(){
	
	
			var tempPos = new Array(j("#" + randomCharacter[currentFigure][0]).position().left,j("#" + randomCharacter[currentFigure][0]).position().top,j("#" + randomCharacter[currentFigure][0]).width());
			var tempWidth = Math.round(j("#bouncerleft").width() *.6);
			
			if(tempWidth==0){
				tempWidth = Math.round(j(window).width()*.15);
			}
		
			//get character width and use for speech bubble width
			//add 30% more
			
			j("#bubble").css("width",tempWidth + (tempWidth*.3));
			j("#bubble").css("height",getProportion(j("#bubble").width(),330,266));
			
			j("#dream").css("width",Math.round(j("#bubble").width()*.90));
			j("#dream").css("height",Math.round(j("#bubble").height()*.75));
			
			j("#dream").css("left",Math.round(j("#bubble").width()*.04));
			j("#dream").css("top",Math.round(j("#bubble").height()*.04));
			
			
			j("#bubbleback").attr("width",j("#bubble").width());
			j("#bubbleback").attr("height",j("#bubble").height());
			
			
			var tempFigureName = String(randomCharacter[currentFigure][0]);
			
			var tempPosAdjust = Math.round(0 - j("#bubble").width()/3) - 10;
			
			j("#bubble").css("left",tempPosAdjust);
			j("#bubble").css("top",0 - (j("#bubble").height()+4));
			
			
			var randomDream = Math.round(Math.random()*Number(dreamsImages.length-1));
			//var tempDream = String(dreamsImages[randomDream]).replace(/width=300/,"width=" + j("#bubble").width());

			j("#" + randomCharacter[currentFigure][0] + " #dream").css("background-image","url(" + dreamsImages[randomDream] + ")");
			
}



function restartWalker(){
	
	if(currentFigure>=0){
	
	moveCharacters(randomCharacter[currentFigure][0],randomCharacter[currentFigure][1],randomCharacter[currentFigure][2],randomCharacter[currentFigure][3]);
	}
	return false;
}



function getRandomNumber(){
	var tempRan = new Array()
	tempRan[0] = Math.round(Math.random()*Number(randomCharacter.length-1));
	
	return tempRan;
}

function walkCharacters(character){
	
	if(!ipodOpen && !stopSign){
	//local variable
	
	var ran = getRandomNumber();
	
	while(ran[0] == character){
		ran = getRandomNumber();
		
		if(!cafeHidden && ran[0]>=10){
			ran[0] = character;
		}//end if
	}
	
	currentFigure=ran[0];
		
	moveCharacters(randomCharacter[ran[0]][0],randomCharacter[ran[0]][1],randomCharacter[ran[0]][2],randomCharacter[ran[0]][3]);
	}
}


function showPortfolio()
{
			
	if(!showingImages){
	j("#ipod").css("display","block");
	j("#ipod").css("top",interfaceHeight);
	showipod();
	}
	
	return false;

}


var introHidden = false;
var cafeHidden = true;
var cafeAniDone = false;

/*show the cafe as a background*/
function resizeCafe(){
	
	if(!cafeHidden){
		j("#windowmiddle").width(j(window).width()*.90);
		j("#windowmiddle").height(getProportion(j("#windowmiddle").width(),1500,847));
		
		var topAdjust = .70;
		
		var tempWin = (j(window).width() - j("#windowmiddle").width())/2;
		var tempTop = (interfaceHeight - j("#windowmiddle").height())/2;
		var tempTop1 = tempTop - (tempTop*topAdjust);
		
		j("#windowleft").css("width",tempWin);
		j("#windowleft").css("height",j("#windowmiddle").height());
		j("#windowleft").css("left",0);
		j("#windowleft").css("top",tempTop1);
		
		j("#windowmiddle").css("left",tempWin);
		j("#windowmiddle").css("top",tempTop1);
		
		j("#windowright").css("width",tempWin);
		j("#windowright").css("height",j("#windowmiddle").height());
		j("#windowright").css("left",j("#windowmiddle").width() + tempWin);
		j("#windowright").css("top",tempTop1);
		
		
		var tempHeight = (interfaceHeight - j("#windowmiddle").height())/2;
		var tempHeight1 = tempHeight - (tempHeight*topAdjust);
		var tempHeight2 = tempHeight + (tempHeight*topAdjust);
		
		j("#windowtop").css("width",j(window).width());
		j("#windowtop").css("height",tempHeight1);
		j("#windowtop").css("left",0);
		j("#windowtop").css("top",0);
		
		j("#windowbottom").css("width",j(window).width());
		j("#windowbottom").css("height",tempHeight2);
		j("#windowbottom").css("left",0);
		j("#windowbottom").css("top",j("#windowmiddle").height() + tempHeight1);
		
		j("#cafetable").css("width",j(window).width()*.95);
		j("#cafetable").css("height",getProportion(j("#cafetable").width(),1000,749));
		
		tempWin = (j(window).width() - j("#cafetable").width())/2;
		j("#cafetable").css("left",tempWin);
		
		j("#cafetableback").css("width",j("#cafetable").width());
		j("#cafetableback").css("height",getProportion(j("#cafetable").width(),1000,221));
		j("#cafetableback").css("left",tempWin);
		
		
		j("#cafechairs1").css("width",j("#windowmiddle").width()*.5);
		j("#cafechairs1").css("height",getProportion(j("#cafechairs1").width(),700,410));
		j("#cafechairs1").css("left",j("#windowmiddle").position().left);
		
		j("#cafechairs2").css("width",j("#windowmiddle").width()*.5);
		j("#cafechairs2").css("height",getProportion(j("#cafechairs2").width(),700,413));
		j("#cafechairs2").css("left",j("#windowmiddle").width()-(j("#cafechairs2").width()*.85));
		
		var tempIndice = 0;
		if(cafeHidden){
			tempIndice = 1;
	
		}
		
		//chairs 1 top placement
		var tempChair1 = j("#windowmiddle").height()-(j("#cafechairs1").height()/2);
		//chairs 2 top placement
		var tempChair2 = j("#windowmiddle").height()-(j("#cafechairs2").height()/2);
		
		if(interfaceHeight>j(window).width()){
			tempChair1 += (tempChair1 * .4);
			tempChair2 += (tempChair2 * .4);
		}
	
		j("#cafechairs1").css("top",tempChair1 + (tempChair1*.05));	
		j("#cafechairs2").css("top",tempChair2 + (tempChair2*.05));
		j("#cafetable").css("top",interfaceHeight - (j("#cafetable").height()/3));
		j("#cafetableback").css("top",interfaceHeight - (j("#cafetable").height()/3));
		j("#cafetableback").fadeTo(0,.7);
		
		
		var signScale = .1;
		j("#scene").show();
		j("#scene").css("width",j(window).width()*signScale);
		
		var signHeight = getProportion(j(window).width()*signScale,200,112);
		
		j("#scene").css("height",signHeight);
		j("#scene").css("top",j(window).height()*.2);
		j("#scene").css("left",j(window).width()*.06);
		
		
		if(j("#scene img").length==0){
			j("#scene").append("<img src='images/sign_exit.gif' width='" + j(window).width()*signScale + "' height='" + signHeight + "'/>");
		}
		else{
			j("#scene img").attr({"width":j(window).width()*signScale,"height":signHeight});
		}
		
	}
}

function changeScene(){
	
	j("#scene").hide();
	j("#characterAni").hide();
	
	if(cafeHidden){
		showCafe();
		hideOutside();
	}
	else{
		hideCafe();
		showOutside();
	}
}

function hideOutside(){
	j("#figures").hide();
	j("#introani").css("display","none");
	j("#loungearea").css("display","none");
	introHidden = true;
}

function hideCafe(){
	j("#figures").hide();
	j("#cafe").css("display","none");
	j("#cafetableback").css("display","none");
	j("#cafetable").css("display","none");
	j("#cafewindow").css("display","none");
	cafeHidden = true;
}


function showOutside(){
	
	if(!contactOpen && !jiverOpen){
	j("#cars").show();
	}
	
	j("#policeleft").show();
	j("#policeright").show();
	
	j("#waiterleft").hide();
	j("#waiterright").hide();
	
	introHidden = false;
	cafeHidden = true;

	
	j('#introani').fadeIn(500, function(){		
		j('#loungearea').fadeIn(500,function(){		
			resizeFigures();
			j("#figures").show();
			j("#characterAni").show();
			resizelounge();
		});
	});
	
	
	
}

function showCafe(){
	
	j("#cars").hide();
	j("#policeleft").hide();
	j("#policeright").hide();
	
	j("#waiterleft").show();
	j("#waiterright").show();
	
	j("#cafetableback").css("display","block");
	j("#cafetable").css("display","block");
	j("#cafewindow").css("display","block");
	
	introHidden = true;
	cafeHidden = false;
	
	resizeCafe();
	
	j('#cafe').fadeIn(500, function(){	
		j("#figures").show();
		j("#characterAni").show();
		resizeFigures();
	});

	return false;
}

//images to check if loaded starts function
var imagesToPreload = Array();
imagesToPreload[0] = "#handy1";
imagesToPreload[1] = "#handy2";
imagesToPreload[2] = "#handy3";
imagesToPreload[3] = "#handy4";
imagesToPreload[4] = "#handy5";
imagesToPreload[5] = "#handy6";
imagesToPreload[6] = "#ladder";
imagesToPreload[7] = "#sign";
imagesToPreload[8] = "#lounge";
imagesToPreload[9] = "#cafetable";
imagesToPreload[10] = "#cafetableback";
imagesToPreload[11] = "#cafechairs1";
imagesToPreload[12] = "#cafechairs2";
imagesToPreload[13] = "#windowmiddle";
imagesToPreload[14] = "#ipodclose";
imagesToPreload[15] = "#ipodhand1";
imagesToPreload[16] = "#ipodhand2";
imagesToPreload[17] = "#lounge";
imagesToPreload[18] = "#gobubbleart";
imagesToPreload[19] = "#modeltright";
imagesToPreload[20] = "#modeltleft";
imagesToPreload[21] = "#chevyright";
imagesToPreload[22] = "#chevyleft";
imagesToPreload[23] = "#bouncerright1";
imagesToPreload[24] = "#bouncerright2";
imagesToPreload[25] = "#bouncerleft1";
imagesToPreload[26] = "#bouncerleft2";
imagesToPreload[27] = "#guyright1";
imagesToPreload[28] = "#guyright2";
imagesToPreload[29] = "#guyleft1";
imagesToPreload[30] = "#guyleft2";
imagesToPreload[31] = "#girlleft1";
imagesToPreload[32] = "#girlleft2";
imagesToPreload[33] = "#girlright1";
imagesToPreload[34] = "#girlright2";
imagesToPreload[35] = "#policeright1";
imagesToPreload[36] = "#policeright2";
imagesToPreload[37] = "#policeleft1";
imagesToPreload[38] = "#policeleft2";
imagesToPreload[39] = "#waiterright1";
imagesToPreload[40] = "#waiterright2";
imagesToPreload[41] = "#waiterleft1";
imagesToPreload[42] = "#waiterleft2";

var imageLoaded = 0;
var loadChecker;

function showHidePreloadedImage(visibility){
	for(i=0;i<imagesToPreload.length;i++){
		
		j(imagesToPreload[i]).css('visibility',visibility);
	}
}

function loadMessageText(textToShow){
	j("#loadMessage").html(textToShow);
}

function createLoadMessage(){
		j("#loadMessage").css({"top":-200,"left":(j(window).width()/2) - (j(window).width()*.2)/2,"width":(j(window).width()*.2)});
		j("#loadMessage").show();
		j('#loadMessage').animate({top: (j(window).scrollTop() + (j(window).height()/2))}, 200, 'linear');
}

function startWebsite(){
	
	if(imageLoaded==0){
		createLoadMessage();
	}
	
	if(j(imagesToPreload[imageLoaded]).attr('complete')){
		imageLoaded++;
	}

	loadMessageText("Loading: " + imageLoaded + " of " + imagesToPreload.length);

	if(imageLoaded>=imagesToPreload.length){
		clearInterval(loadChecker);
		imageLoaded = 0;
		
		
		j("#loadMessage").hide();
		j("#loadMessage").empty();
		showHidePreloadedImage('visible');
		
		movehandy();
		moveElements();		
		u1XmlLoader("illos.xml",processDreams);
		
		resizelounge();
		resizeCafe();
		resizeFigures();
		resizeStopper();
		
		clearInterval(loadChecker);
		loadChecker = null;
		
	}
	
}



var interfaceWidth;
var interfaceHeight;

function findSquare(){
	
	//(Repro width / original width) * original height = repro height;
	
	//optimum viewing = 1024 x 840
	interfaceWidth = j(window).width();
	interfaceHeight = getProportion(j(window).width(),1024,780);
	
	interfaceHeight = Math.round(interfaceHeight + interfaceHeight*.1);
	
}


function resumeResizer(){
	
	var graphicSizes;
	
	switch(currentResumeChar){
	
	case 'police':
	graphicSizes = Array(350,602);
	break;
	
	case 'waiter':
	graphicSizes = Array(340,667);
	break;
	
	case 'bouncer':
	graphicSizes = Array(387,602);
	break
	
	}
		
	
	//gets 17% of window width and gets  new height of policeman
	var tempCurrent = Array(j(window).width()*.17,getProportion(j(window).width()*.17,graphicSizes[0],graphicSizes[1]));
	
	//adds 90% to tempCurrent[0] for policeman's full width includes hand with resume
	//add 90% to tempCurrent[1] for policeman's full width includes hand with resume
	var temp = Array(tempCurrent[0] + (tempCurrent[0]*.9),tempCurrent[1] + (tempCurrent[1]*.9));

	return temp;
}


//resize resume holder
function resizeJiver(){

	
	var tempSizer = resumeResizer();
	
	var jiverTop = j("#sidewalk").position().top - (j("#sidewalk").position().top*resumeCoors[0]);
	
	j("#jiver").css({"left": Math.round(j(window).width()*.05) + "px","top":jiverTop});

	j("#jiver").css({'width': tempSizer[0], "height":tempSizer[1] });
	j("#jiverright1").attr({'width': tempSizer[0], "height":tempSizer[1] });
	j("#jiverright2").attr({'width': tempSizer[0], "height":tempSizer[1] });
	j("#jiverright1").css({'width': tempSizer[0], "height":tempSizer[1] });
	j("#jiverright2").css({'width': tempSizer[0], "height":tempSizer[1] });
	

	if(j("#jiverhand").length>0){
		
		//subtract 80% from top position of resume character
		var jiveResume = (jiverTop - jiverTop *resumeCoors[1]);
		
		j("#jiverhand").css({"left": tempSizer[0]*resumeCoors[2] + "px", "top": jiveResume + "px"});
		
		if(!contactOpen){
			j("#jiverhandtop").attr({'width':tempSizer[0]*2,'height':getProportion(tempSizer[0]*2,800,177)});
		}
		else{
			j("#jiverhandtop").attr({'width':tempSizer[0]*2,'height':getProportion(tempSizer[0]*2,549,452)});
		}
		var tempBack = j("#jiverhandmid").css('background-image');
		
		/*
		tempBack = String(tempBack).replace(/width=([0-9]){2,4}/,"width=" + tempSizer[0]*2);
		j("#jiverhandmid").css({'width':tempSizer[0]*2, 'background-image': tempBack});
		*/
		
		j("#jiverhandmid").css({'width':Number(tempSizer[0]*2)-6});
		
		j("#jiverhandbot").attr({'width':tempSizer[0]*2,'height':getProportion(tempSizer[0]*2,800,19)});
		
		j("#jiverclose").attr({'width': (tempSizer[0]*2)*.06 ,'height': (tempSizer[0]*2)*.06});
		j("#jiverclose").css({'left': Math.round((tempSizer[0]*2) - (tempSizer[0]*2)*.06) + "px", 'top':(jiveResume*.5)});
		
		
		j("#jiverstop").attr({'width':tempSizer[0],'height':tempSizer[1]});
		
		
		if(j("#bcard").length>0){
			j("#bcard").css({"width":j("#jiverhandtop").width()*.75 + "px", "top":j("#jiverhandtop").height()*.35 + "px"});
		}
		
		
	}// end if
	
}


var currentResumeChar;
var resumeCoors;
var contactOpen = false;
var jiverOpen;



function hideResume(resumeReselect){
	
		resumeOpen=false;
	
		stopClouds();
		desactivateButns();
	
		if(j("#jiver").length > 0){
			
			j("#jiverhand").remove();
			
			j("#jiverright1").attr("src",j("#" + currentResumeChar + "left1").attr("src"));
			j("#jiverright2").attr("src",j("#" + currentResumeChar + "left2").attr("src"));
			j("#jiverstop").hide();
			
		
			j("#jiver").animate({
				left: j(window).width()
				}, 1500, 'linear', function(){
					clearInterval(resumeInterval);
					resumeInterval = null;
					//j("#test").append(" hideResume" + resumeInterval);
					
					activateButns();
						
					j("#jiver").empty();
					j("#jiver").remove();
									
					if(resumeReselect){
						showResume();
					}
					else{
						jiverOpen=false;
						contactOpen=false;
					}
					
					if(cafeHidden && !contactOpen && !jiverOpen){
						j("#cars").show();
					}
					
					moveClouds();
					
			});
				
			resumeInterval = setInterval(function(){rotateObjectsCopy('jiverright1','jiverright2')}, 60);
		}
	return false;
}

//analyzes if a resume is on stage and display of hides depending on results.
function resumeTriage(){

		jiverOpen=true;
		//contactOpen=false;
		
		//hide cars
		j("#cars").hide();
		
		if(j("#jiver").length<=0){
			showResume();
	
		}
		else{
			hideResume(true);
		}

}

var resumeInterval;
var resumeOpen =false;

//shows character with resume
function showResume(){
	
	
	resumeOpen=true;
	
	stopClouds();
	desactivateButns();

	
	var tempCurrent;
	var tempSizer;
	var graphicSizes;
	

	if(!contactOpen){
		if(!introHidden){	
			currentResumeChar = "police";
			resumeCoors = new Array(.6,.8,.75);
		}
		else{
			currentResumeChar = "waiter";	
			resumeCoors = new Array(.7,.7,.85);
		}
	}
	else{
		currentResumeChar = "bouncer";	
		resumeCoors = new Array(.5,.65,.8);
	}
	
	

	tempSizer = resumeResizer();
		
	var resumeStop = Math.round(j(window).width()*.05);

	//removes jiver element if on stage
	hideResume();
	
	
	var jiver = j("<div id='jiver'></div>");
	j(jiver).css("left",j(window).width() + tempSizer[0] + "px");
	j(jiver).append("<img src='" + j("#" + currentResumeChar + "right1").attr("src")  + "' id='jiverright1' width='" + tempSizer[0] + "' height='" + tempSizer[1] + "' />");
	j(jiver).append("<img src='" + j("#" + currentResumeChar + "right2").attr("src")  + "' id='jiverright2' width='" + tempSizer[0] + "' height='" + tempSizer[1] + "' />");
	
	j(jiver).css("width",tempSizer[0]);
	j("#jiverright1").css("width",tempSizer[0]);
	j("#jiverright2").css("width",tempSizer[0]);
	
	j(jiver).css("height",tempSizer[1]);
	j("#jiverright1").css("height",tempSizer[1]);
	j("#jiverright2").css("height",tempSizer[1]);
	
	
	//set resume hand attributes and positioning
	
	// get sidewalk top position and subtract 60% of that.
	var jiverTop = j("#sidewalk").position().top - (j("#sidewalk").position().top*resumeCoors[0]);
	
	//subtract 80% from top position of resume character
	var jiveResume = (jiverTop - jiverTop *resumeCoors[1])
	
	var resume = j("<div id='jiverhand' style='left:" + tempSizer[0]*resumeCoors[2] + "px; top:" + jiveResume + "px;'></div>");
	
	if(!contactOpen){
		j(resume).append("<img id='jiverhandtop' src='images/" + currentResumeChar + "_hand_top.gif' width='" + tempSizer[0]*2  + "' height='" + getProportion(tempSizer[0]*2,800,177) + "' />");

		j(resume).append("<div id='jiverhandmid' style='width:" + Number(Math.round(tempSizer[0]*2) - 6) + "px;'></div>");
		
		
		j(resume).append("<img id='jiverhandbot' src='images/" + currentResumeChar + "_hand_bot.gif' width='" + tempSizer[0]*2  + "' height='" + getProportion(tempSizer[0]*2,800,19) + "'/>");
	}
	else{
		j(resume).append(bcardInfo + "<img id='jiverhandtop' src='images/" + currentResumeChar + "_hand.gif' width='" + tempSizer[0]*2  + "' height='" + getProportion(tempSizer[0]*2,549,452) + "' />");
	}
	
	
	j(resume).append("<a href=''><img id='jiverclose' src='images/butn_close.png' width='"+ (tempSizer[0]*2)*.06 + "' height='" + (tempSizer[0]*2)*.06 + "' style='left: " + Number((tempSizer[0]*2) - (tempSizer[0]*2)*.06) + "px; top:" + (jiveResume*.5) +  "px;'/></a>");
	
	
	j("body").append(j(resume));
	
	
	resumeLoader();
	
	j("#jiverclose").bind('click',function(){
		hideResume();
		return false;
	});
	

	j(jiver).append("<img id='jiverstop' src='images/" + currentResumeChar + "_stand.gif' width='" + tempSizer[0] + "' height='" + tempSizer[1] + "' />");
	
	
	j(jiver).css("top",jiverTop);
	
	if(j("#bcard").length>0){
		j("#bcard").css({"width":j("#jiverhandtop").width()*.75 + "px", "top":j("#jiverhandtop").height()*.35 + "px"});
	}
	
	j("#figures").append(j(jiver));

	j(jiver).animate({
	left: resumeStop
	}, 2000, 'linear', function(){
		clearInterval(resumeInterval);
		resumeInterval = null;
		//j("#test").append(" showResume" + resumeInterval);
		
		activateButns();
		j('#jiverright1').hide();
		j('#jiverright2').hide();
		j('#jiverstop').show();
		j('#jiverhand').show();
		});
	
		moveClouds();

	
		clearInterval(resumeInterval);
		resumeInterval = setInterval(function(){rotateObjectsCopy('jiverright1','jiverright2')}, 60);
		
	//stopWalkers();

	return false;
}


function resumeLoader(){
	
	 j.ajax({
    	url: "resume.html",
    	dataType: "html",
		isLocal: true,
    	success: function(data, textStatus, jqXHR){
				j("#jiverhandmid").append("<div id='resumeText'>" + data + "</div>");
				//j("#jiverhandmid").append(data);
			}
	});

}

function activateButns(){
		j('#nav').animate({top: 10}, 500, 'linear');

}

function desactivateButns(){
		j('#nav').animate({top: -100}, 500, 'linear');	
}


j(window).resize(function() {
	findSquare();				  
						  
	moveElements();
	resizeStopper();
	resizeipod();
	resizelounge();
	resizeCafe();
	resizeIpodPortfolio();
	resizeFigures();
	resizeWeather();
	
	resizePopart();
	
	if(j("#jiver").length>0){
	resizeJiver();
	};
	
	
});

j(document).ready(
				  
	function()
	{		
		
		findSquare();
	
		clearInterval(loadChecker);
		loadChecker = setInterval(startWebsite,50);
		showHidePreloadedImage('hidden');
		
		j("#scene").bind('click',function(){changeScene(); return false;});		
		
		j("#closer").bind('click',hideProjectInfo);
		j("#ipodclose").bind('click',function(){hideIpod(true); return false;});
		
		j("#home").bind('click',function(){contactOpen=true; resumeTriage(); hideIpod(true); return false;});
		j("#work").bind('click',function(){showPortfolio(); contactOpen=false; hideResume(false); return false;});
		j("#contact").bind('click',function(){ contactOpen=false; resumeTriage(); hideIpod(true); return false;});
		
		j("#characterAni img").bind("click",function(){stopperAction(); return false;});


		j("#next").bind("click",function(){			 
			changePages();
			return false;
		});
		
		j("#prev").bind("click",function(){
			changePages('prev');
			return false;
		});
		
		j("#test").html("<a href='./vegan.php'>View the Vegan Menu!</a>");
		
		//j("#gobubbleart").bind("click",restartWalker);
	
	}
);

