$(document).ready(function(){
	/*
	if (jQuery.browser.safari && (navigator.appVersion.indexOf('3.') != -1)) {
     	alert("Warning Safari 3 not supported!");
	}
	*/
	$.ajaxSetup({cache: false});
	$('#bigimg').css('overflow','hidden');
	//$('#masked').draggable();
	$('#openscroll').hide();
	$('#zoombox').hide();
	$('#scrollbox').hide();
	$('#rightscroll').hide();
	$('#galdisplay').hide();
	$('#gbox').hide();
	$('#galimg').hide();
	//$('#logo').css("visibility", "hidden");
	$("#geographic").accordion({ autoHeight: false },{ active: false },{ collapsible: true });
	$("#lefttop").accordion({ autoHeight: false },{ active: false }, { collapsible: true });
	$("#multi").accordion({ autoHeight: false },{ active: false }, { collapsible: true });
	initLoad("Front");
	$('a').livequery('click', function(event) {
		var pdf = $("#"+this.id).hasClass("pdf");
		if (event.target.id.substr(0,2) == "a_" || pdf == true) {
			// dodging preventDefault so link will load
			//
		} else {
		// banner ad switch
		/*
			// removed so js ad stays in top banner
		if(this.id.substr(0,2) == "c_") {
			var adsw = this.id.split("_");
			frontAdControl(adsw[1]);
		}
		*/
		if(event.target.id.substr(0,2) == "p_") {
			//alert("print");
			window.open("MMagOpeningsGuide.html");
		}
		if(event.target.id.substr(0,2) == "m_") {
			// big ugly switch for map front graphics
			$("#openscroll").hide();
			$('#galdisplay').hide();
			var mst = event.target.id.split("_");
			var urlimg = mst[1]+'.jpg';
			if(mst[1] == "Front") {// GIF SWITCH
				urlimg = mst[1]+'.gif';
				if(curcenter != "none") {
					$("#centerbanner").html('');
				}
			}
			if(mst[1] == "Philadelphia") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Seoul") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Hongdae") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Gangnam-gu") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Insa-dong") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "SantaFe") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "HongKong") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Tokyo") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Caochangdi") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Jiuchang") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Dashanzi") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Singapore") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "London") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Berlin") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Halleamwasser") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Frankfurt") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Munich") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Paris") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Madrid") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Florence") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Basel") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Taipei") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Moscow") {
				urlimg = 'Front.gif';
			}
			if(mst[1] == "Village") {// LES SWITCH
				urlimg = 'LES.png';
			}
			if(mst[1] == "Soho") {// Soho SWITCH
				urlimg = 'LES.png';
			}
			if(mst[1] == "Midtown") {// Midtown
				urlimg = 'Uptown.jpg';
			}
			if(mst[1] == "Chelsea") {// Chelsea png
				urlimg = 'Chelsea.png';
				//urlimg = 'Chelsea.gif';
			}
			$("#centerbox").fadeOut('slow', function() {
				$('#centerbox').html('');
				img = new Image();
				$(img).load(function() {
					$('#centerbox').append(this);
					$('#centerbox').fadeIn();
					$(this).attr('id', 'masked');
					$('#masked').draggable();
					if(urlimg == "Front.gif") {//mst[1] == "Seoul" || mst[1] == "Front") {
						$('#logo').css("visibility", "hidden");
						$('#scrollbox').hide();
						$('#rightscroll').hide();
						// RIGHT SCROLL REMOVE
					} else {
						//
						$('#logo').css("visibility", "visible");
						$('#scrollbox').show();
						$('#rightscroll').show();
						// RIGHT SCROLL REMOVE
					}
					var mright="pages/"+mst[1]+"_right.html";
					$.get(mright, function(data) {
  						$('#right').html(data);
  						$("#multi").accordion({ autoHeight: false },{ active: false }, { collapsible: true });
  						dstate = mst[1];
					});
					if(zoomd == false) {
						//$('#zoombox').show();
						$('#scrollbox').show();
						zoomd = true;
					}
					$('#rightscroll').show();
					// RIGHT SCROLL REMOVE
				})
				.attr('src', 'maps/'+urlimg);
			});				
		}
		if (event.target.id.substr(0,2) == "g_") {
			$("#openscroll").hide();
			event.preventDefault();
			// cache is now clearing in ajaxSetup
			var npath = "pages/"+dstate+"_galleries.html #"+event.target.id;
			$('#ginterior').load(npath, function() {
				$('#galdisplay').show();
			});
			
		} else {
		switch(event.target.id) {
			case "openings" :
				var now = new Date();
				var dday = now.getDate();
				var mday = now.getMonth();
				var yday = now.getFullYear();
				var cmpday = yday+"_"+mday+"_"+dday;
				$('#galdisplay').hide();
				$('#scrollbox').hide();
				$("#centerbox").fadeOut('slow', function() {
					var dapath = "pages/openings.html";// #"+"2011_0_27";
					$('#centerbox').load(dapath, function() {
  						$(".opmenu").accordion({ autoHeight: false },{ active: false },{ collapsible: true });
						$('#centerbox').fadeIn('slow', function(){
							$("#openpage").draggable({ axis: 'y' }, { containment: [0,-800,0,91] });
							$("#openscroll").show();
							$('#logo').css("visibility", "visible");
						});
					});
				});
			break;
			case "zoomin" :
				var wt = $("#masked").width();
				var ht = $("#masked").width();
				var rat = (wt / ht) * zamt;
				var nw = wt + zamt;
				var nh = ht + rat;
				$("#masked").css("width", nw);
				$("#masked").css("height", nh);
			break;
			case "zoomout" :
				var wt = $("#masked").width();
				var ht = $("#masked").width();
				var rat = (wt / ht) * zamt;
				var nw = wt + zamt;
				var nh = ht + rat;
				var nw = wt - zamt;
				var nh = ht - rat;
				$("#masked").css("width", nw);
				$("#masked").css("height", nh);			
			break;
		}
		event.preventDefault();
		}
		}
	});
	$("#openup").click(function() {
		$("#openpage").animate({"top": "+=50px"}, "slow");
	});
	$("#opendown").click(function() {
		$("#openpage").animate({"top": "-=50px"}, "slow");
	});
	
	$("#larrow").click(function(){
  		$("#masked").animate({"left": "+=50px"}, "slow");
	});
	$("#uarrow").click(function(){
  		$("#masked").animate({"top": "+=50px"}, "slow");
	});
	$("#rarrow").click(function(){
  		$("#masked").animate({"left": "-=50px"}, "slow");
	});
	$("#darrow").click(function(){
  		$("#masked").animate({"top": "-=50px"}, "slow");
	});
	$("#ruarrow").click(function() {
		yp = $("#galleries").css("top");
		nyp = yp.replace('px', '');
		if(nyp < 0) {
			$("#galleries").animate({"top": "+=100px"}, "slow");
		}
	});
	$("#rdarrow").click(function() {
		$("#galleries").animate({"top": "-=100px"}, "slow");
	});
	$("#luarrow").click(function() {
		gyp = $("#geographic").css("top");
		ngyp = gyp.replace('px', '');
		if(ngyp < 0) {
			$("#geographic").animate({"top": "+=100px"}, "slow");
		}
	});
	$("#ldarrow").click(function() {
		$("#geographic").animate({"top": "-=100px"}, "slow");
	});
	$("#galdisplay").click(function() {
		$("#galdisplay").fadeOut();
	});
	//initTopBanner();
});

var logov = false;
var zamt = 50;
var zoomd = false;
var dstate = "front";

function initLoad(pg) {
	$('#centerbox').html('');
	img = new Image();
	$(img).load(function() {
		$('#centerbox').append(this);
		//$('#centerbox').fadeIn('fast', playBanner());
		$('#centerbox').fadeIn();
		$(this).attr('id', 'masked');
		//$('#masked').draggable();
		if(pg == "Front") {
			$('#logo').css("visibility", "hidden");
			$('#rightscroll').hide();
		} else {
			$('#logo').css("visibility", "visible");
		}
		var mright="pages/"+pg+"_right.html";
		$.get(mright, function(data) {
  			$('#right').html(data);
  			$("#multi").accordion({ autoHeight: false },{ active: false }, { collapsible: true });
  			dstate = pg;
		});
		if(pg != "Front") {
			$('#scrollbox').show();
		}
		zoomd = true;
	})
	//.attr('src', 'maps/'+pg+'.jpg');
	.attr('src', 'maps/'+pg+'.gif');
	//.attr('src', 'maps/'+pg+'.png');
	
	
	//
	$("#centerbanner").hide();
	//playBanner();
}



var curcenter = "none";
var cityads = new Array();
var adpath = "img/ads/";
//cityads['NewYork'] = "tas_m-banner.gif";
cityads['NewYork'] = "ban.jpg";
var adtype = new Array();
adtype['NewYork'] = "js";// or img
var adinfo = new Array();// instead of xml quick dirty info
adinfo[0] = [468,60];
adinfo[1] = "#e9e2bf";
adinfo[2] = "directartsworldsfair.jpg";
//adinfo[3] = "Causey

//$("#centerbanner").append("banner");
//$("#centerbanner").css("color", "red");

function frontAdControl(city) {
	if(curcenter != city) {
		$("#centerbanner").html('');
	}
	if(cityads[city] != undefined) {
		// adtype switch goes here
		// js play
	
	/*
		// img load
		//
	
		var adimg = new Image();
		//$('#centerbanner').load(adpath+cityads[city]); FREAKY!
		$(adimg).load(function() {
			$('#centerbanner').append(this); 
			})
		.attr('src', adpath+cityads[city]); 		
		}
	*/
	}
	curcenter = city;
}

	
