var screenWidth = 0;
var screenHeight = 0;
var pmvWidth = 0;
var pmvHeight = 0;
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}
function windowOpen(filename,windowname,properties) {
	mywindow = window.open(filename,windowname,properties);
}
function embedHTML5(){
	if(!html5Active){
		$(document).ready(function() {
			document.getElementById('pm_viewer_holder').innerHTML = "<div id='pm_viewer'></div>";
			document.getElementById('pm_viewer_holder').style.width = pmvWidth+"px";
			document.getElementById('pm_viewer_holder').style.height = pmvHeight+"px";
			document.getElementById('pm_viewer').style.width = pmvWidth+"px";
			document.getElementById('pm_viewer').style.height = pmvHeight+"px";
			Z.showImage('pm_viewer',pmPath,'zNavigatorWidth='+pmNavWidth+'&zNavigatorHeight='+pmNavHeight+zoomLocation);
			html5Active = 1;
		});
	}
}
function GetWindowSize() {
	screenWidth =$(window).width();
	screenHeight =$(window).height();
}
function createViewer() {
	//alert("viewX="+viewX+"<br />viewY="+viewY+"<br />zoomLevel="+zoomLevel+"<br />pmTourY="+pmTourY)
	if (hasFlash) {
		$(document).ready(function() {
			document.getElementById('pm_viewer_holder').innerHTML = "<div id='pm_viewer'></div>";
			var swfVersionStr = "9.0.0";
			var flashvars = {
				PictureMosaicsVars: pmParams,
				pmNavigatorX: (pmvWidth-pmNavWidth),
				pmNavigatorY: (pmvHeight-pmNavHeight),
				pmInitialX: viewX,
				pmInitialY: viewY,
				pmInitialZoom: zoomLevel,
				pmTourBoxPosX: pmTourXOffset,
				pmTourBoxPosY: pmTourY
			};
			var params = {
				menu: "false",
				quality: "high",
				bgcolor: "#000",
				wmode: "transparent",
				allowscriptaccess: "sameDomain"
			};
			var attributes = {
				id: "pmMosaic",
				name: "pmMosaic"
			};
			swfobject.embedSWF(swfFile, "pm_viewer", pmvWidth, pmvHeight, swfVersionStr, "expressInstall.swf", flashvars, params, attributes);
			flashActive = 1;
		});
	}else {
		embedHTML5();
	}
	
}
function setSize() {
	GetWindowSize();
	var tempWidth = Math.round(screenWidth - 100);
	var tempHeight = Math.floor(tempWidth * 0.6);
	//alert("ScreenHeight: "+screenHeight+"<br />tempHeight: "+tempHeight);
	if(source == 'web'){
		if(tempHeight > (screenHeight-275) ){
			tempWidth = Math.round( (screenHeight-275) / 0.6 );
			tempHeight = Math.floor(tempWidth * 0.6);
		}
	}
	if(tempWidth <= 760) {
		tempWidth = 760;
		tempHeight = 456;
	}
	if(tempWidth >= 1300) {
		tempWidth = 1300;
		tempHeight = 780;
	}
	if(embed_type != ''){
		tempWidth = Math.round(screenWidth);
		tempHeight = Math.floor(tempWidth * 0.6);
	}
	pmvHeight = tempHeight;
	pmvWidth = tempWidth;
	if(source == 'web'){
		if(embed_type == ''){
			document.getElementById('outer').style.width = (pmvWidth  + 100)+"px";
			//document.getElementById('popular_keyword_container').style.width = (pmvWidth - 165)+"px";
			//document.getElementById('recently_added_container').style.width = (pmvWidth - 165)+"px";
			//document.getElementById('friends_container').style.width = (pmvWidth - 165)+"px";
			$('div.jcarousel-container-horizontal').css('width', (pmvWidth - 165)+'px');
			$('div.jcarousel-clip-horizontal').css('width', (pmvWidth - 165)+'px');
			document.getElementById('chatter_drop').style.height = (pmvHeight+59)+'px';
			document.getElementById('scroll-pane').style.height = (pmvHeight+59)+'px';
			$(function(){
				$('#scroll-pane').jScrollPane({showArrows: true, horizontalGutter: 10});
			});
			if(screenHeight < 1140){
				document.body.style.height= "900px";
			}
		}else{
			document.getElementById('outer').style.width = pmvWidth+"px";
		}
		if(pmvWidth >= 892){
			document.getElementById('button_upload').style.width = "50%";
			document.getElementById('button_pcontest').style.width = "144px";
			document.getElementById('button_shelter').style.width = "50%";
			document.getElementById('button_shelter').innerHTML = '<img class="click" style="margin:0;" src="images/shelters_button.png" onclick="openShadowBox(660,630,\'top_spcas.php\');" alt="contest" onmouseover="rollOver(this,\'images/shelters_hover.png\')" onmouseout="rollOver(this,\'images/shelters_button.png\')"/>';
		}
		if(pmvWidth < 892){
			document.getElementById('button_upload').style.width = "50%";
			document.getElementById('button_pcontest').style.width = "50%";
			document.getElementById('button_shelter').style.width = "0px";
			document.getElementById('button_shelter').innerHTML = '';
		}
	}
	var viewerHolder = document.getElementById('viewer_holder');
	viewerHolder.style.width = pmvWidth+"px";
	viewerHolder.style.height = pmvHeight+"px";
}
function browserResize() {
	document.getElementById("pmMosaic").flashCallResize();
	setSize();
	updateView();
}
function flashCheckTourState() {
	sendTourState();
}
function sendTourState() {
	//alert("hotspotIndex="+hotspotIndex+"<br/>activeTour="+activeTour);
	document.getElementById("pmMosaic").flashSendTourState(hotspotIndex,activeTour);
	//getFlashMovie("pmMosaic").flashSendTourState(hotspotIndex,activeTour);
}
function checkResize() {
	browserWidth = screenWidth;
	browserHeight = screenHeight;
	GetWindowSize();
	if ( screenWidth < 1400 || pmvWidth < 1300 ) {
		widthDif = Math.abs(browserWidth-screenWidth);
		heightDif = Math.abs(browserHeight-screenHeight);
		if ( widthDif > 60 || heightDif > 40) {
			browserResize();
		}
	}
}
function noResize() {
	document.getElementById("resize_window_container").style.visibility="hidden";
	document.getElementById("resize_window_container").style.display="none";
}
function getViewerWidth() {
	return pmvWidth;
}
function getViewerHeight() {
	return pmvHeight;
}

