// javascript:void(prompt('',gApplication.getMap().getCenter()));

function makeStudio(title,manager,phone,address,promoURL,latT,longT,blurb,studImgs,studLogos) {

	this.title=title;

	this.manager=manager;

	this.phone=phone;

	this.address=address;

	this.promoURL=promoURL;

	this.longT=longT;

	this.latT=latT;

	this.blurb=blurb;

	this.studImgs=studImgs;

	this.studLogos=studLogos;

};

 

var studios = [ 

				new makeStudio("1020 Studios", "Chris Devane", "(323)883-0262", "1020 N Sycamore Ave<br />Los Angeles, CA 90038","http://www.1020studios.com/", 34.089634,-118.342761, "blurb",[],"1020s_logo.jpg"),

				new makeStudio("200 South", "Kelly Fancher", "(323)330-1020", "200 S. La Brea Blvd.<br />Los Angeles, CA 90048","http://200south.com", 34.070698,-118.343611, "10 rooms!",['200s1_t.jpg', '200s2_t.jpg','200s3_t.jpg', '200s4_t.jpg','200s5_t.jpg','200s6_t.jpg'],"200s_logo.jpg"),

				new makeStudio("310 Casting Studios", "Erich Zander", "(310)775-6600", "2329 Purdue Ave<br />Los Angeles, CA 90064","http://310castingstudios.com", 34.034577,-118.441415, "2 full time tech gurus.",['3ten1_t.jpg','3ten2_t.jpg','3ten3_t.jpg','3ten4_t.jpg','3ten5_t.jpg'],"3ten_logo.jpg"),

				new makeStudio("5th Street Studios", "Bobby Stephenson", "(310)458-1100", "1216 5th St<br />Santa Monica, CA  90401","http://5thstreetstudios.net", 34.019277,-118.497009, "blurb.", [], "fif_logo.jpg"),

				new makeStudio("ASG Casting", "Erin Murphy", "(818)762-0200", "4144 Lankershim Blvd # 202<br />North Hollywood, CA 91602","http://www.asgcasting.com/", 34.145832,-118.362387, "blurb",[], "asg_logo.jpg"),

				new makeStudio("broad-cast", "Lily Brawner", "(323)937-0411", "7461 Beverly Blvd<br />Los Angeles, CA 90036","http://www.broad-cast.tv", 34.076169,-118.352753, "blurb",[], "bc_logo.jpg"),

				new makeStudio("Casting Cafe", "Manny Soto", "(310)274-9909", "9000 Santa Monica Blvd<br />West Hollywood, CA 90069","http://www.castingcafe.us/", 34.082973,-118.386698, "blurb",['cafe1_t.jpg','cafe2_t.jpg','cafe3_t.jpg'], "cafe_logo.jpg"),

				new makeStudio("Castaway Studios", "Courtney & Liam", "(310)248-5296", "8899 Beverly Blvd # 206<br />West Hollywood, CA  90048", "http://castawaystudios.com/", 34.077225, -118.386247, "Courtney and Liam will rock your world.",['cw1_t.jpg','cw2_t.jpg','cw3_t.jpg','cw4_t.jpg'], "cw_logo.jpg"),

				new makeStudio("Envision Studios", "Joe Brundige", "(310)451-1515", "1528 6th St Suite 100<br />Santa Monica, CA 90401", "http://envisionstudios.tv/", 34.015797,-118.491347, "Video conferencing gurus.",[], "env_logo.jpg"),

				new makeStudio("Exclusive Casting Studios", "Johnny Franzen", "(323)969-0200", "7700 Sunset Boulevard, Suite 200<br/>Los Angeles, CA 90046","http://www.exclusivecastingstudios.com", 34.098038,-118.3574, "In the heart of the Sunset Strip!",['exc2_t.jpg','exc3_t.jpg','exc4_t.jpg'], "exc_logo.jpg"),

				new makeStudio("HOUSE", "Chadrian McKnight", "(818)980-9803", "855 N Cahuenga Blvd<br />Los Angeles CA 90038","http://www.houseprod.com/", 34.086666,-118.329426, "blurb",['house1_t.jpg','house2_t.jpg','house3_t.jpg','house4_t.jpg'], "house_logo.jpg"),

				new makeStudio("Loudmouth Studios", "Jim Holmes", "(818)980-9803", "11340 Moorpark St<br />Studio City CA 91602","http://www.loudmouthstudios.com/", 34.150101,-118.378305, "blurb",['loud1_t.jpg','loud2_t.jpg','loud3_t.jpg','loud4_t.jpg','loud5_t.jpg'], "loud_logo.jpg"),

				new makeStudio("Sessions West Studios", "Jenny Schmidt", "(310)450-9228", "2601 Ocean Park Blvd., Suite #120<br />Santa Monica, CA  90405", "http://sessionsweststudios.com", 34.017889,-118.458123, "Best studio on Ocean Park!", ['sws1_t.jpg','sws5_t.jpg','sws3_t.jpg','sws4_t.jpg'], "sw_logo.jpg"),

				new makeStudio("Village Studios", "Ava Shevitt", "(310)656-4600", "321 Santa Monica Blvd., Suite #300<br />Santa Monica, CA  90401", "http://villagestudio.net", 34.01565,-118.496141, "Ocean Views!", ['vill1_t.jpg','vill2_t.jpg','vill3_t.jpg','vill4_t.jpg','vill5_t.jpg','vill6_t.jpg','vill7_t.jpg'], "village_logo.jpg"),

				new makeStudio("Zydeco Studios", "Lisa Iannce", "(818)506-0613", "11317 Ventura Blvd<br/>Studio City CA 91604","http://www.shootingfromthehipcasting.com/", 34.140454,-118.376295, "blurb",["zydeco1_t.jpg","zydeco2_t.jpg","zydeco3_t.jpg","zydeco4_t.jpg"], "zy_logo.jpg")

				];

var map;

 

$(document).ready(function(){

	map = new GMap2($("#map").get(0));

	map.addControl(new GLargeMapControl());

	map.disableDoubleClickZoom();

	var tmz = new GLatLng(34.07569681246808, -118.40755462646484);

	map.setCenter(tmz, 11);

	GEvent.addListener(map, "zoomend", function(){$("#message").hide()});

//	GEvent.addListener(map, "click", function(){$("#message").hide()});

	// Create our "cni" marker icon

	var cniIcon = new GIcon();

	cniIcon.image = "/frontend/img_fcstudios/cnidot3.png";

	cniIcon.shadow = "/frontend/img_fcstudios/cnidots3.png";

	cniIcon.iconSize = new GSize(41, 31);

	cniIcon.shadowSize = new GSize(41, 31);

	cniIcon.iconAnchor = new GPoint(20, 31);

	cniIcon.infoWindowAnchor = new GPoint(20, 10);

	

	// Set up our GMarkerOptions object literal

	markerOptions = { icon:cniIcon };

 

	var bounds = map.getBounds();

	var markers = [];

	for (var i = 0; i < studios.length; i++) {

		var point = new GLatLng(studios[i].latT, studios[i].longT);

		marker = new GMarker(point, markerOptions);

		map.addOverlay(marker);

		markers[i] = marker;

	}

	

	$(markers).each(function(i){

	    var d = ['<h3>',

				studios[i].title,

				'</h3><dl><dt>Address:</dt><dd><p>',

				studios[i].address,

				'</p></dd><dt>Manager:</dt><dd>',

				studios[i].manager,

				'</dd><dt>Phone:</dt><dd>',

    			studios[i].phone,

				'</dd><dt>URL:</dt><dd><a target="_blank" href="',

				studios[i].promoURL,

				'">',

				studios[i].promoURL,

				'</a></dd>'].join('');

		var newDiv = $("<div />")

			.attr("id", "div" + i)

			.html(d)

			.click(function(){

				displayPoint(markers[i], i);

				$(".studlisting > div").removeClass("selected");

				$(this).addClass("selected");

			})

			.hover(function(){

				$(this).addClass("hovered");

			},

				  function () {

					$(this).removeClass("hovered");

				  }

			);

		newDiv.appendTo(".studlisting");

	});

	

	$(markers).each(function(i, marker){

		GEvent.addListener(marker, "click", function(){

			var targetDiv = "#div" + i;

			$(".studlisting > div").removeClass("selected");

			$(targetDiv).addClass("selected");

			displayPoint(marker, i);

		});

	});

	

	$("#message").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));

	

	function displayPoint(marker, index){

		$('#message').hide();

		function changeMessage() {

			var markerOffset = map.fromLatLngToDivPixel(marker.getLatLng());

			var tri = '<img src="/frontend/img_fcstudios/tri3.png" class="pointer" />';

			var close = '<a href="#" class="closeMsg">Close Message</a>';

			var c = ['<h4>',

					studios[index].title,

					'</h4><p>',

					studios[index].address,

					'<br />',

					studios[index].phone,

					'<br />',

					studios[index].manager,

					' (Manager)</p><a target="_blank" href="',

					studios[index].promoURL,

					'">Web Site</a>'].join('');

			var studioImages ='';

			var studioImagesArray = studios[index].studImgs;

			$(studioImagesArray).each(function(){

					studioImages = '<img src="/frontend/img_fcstudios/' + this + '"/>' + studioImages;

					});

			var m = ['<div class="galleryContainer"><img id="picScreen" src="/frontend/img_fcstudios/', studios[index].studLogos,'" /><div class="scrollable"><div class="items">', studioImages, '</div></div><a class="prevPage">prev</><a class="nextPage">next</a></div>'].join('');

			$("#message")

				.html(close + tri + c)

				.prepend(m)

				.css({ top:markerOffset.y, left:markerOffset.x });

			$("#message a.closeMsg").click(function(){$("#message").hide()});

			$(".items img").click(function(event){

				event.stopPropagation();

				// calclulate large image's URL by taking off the _t appendage

				var url = $(this).attr("src").replace("_t", ""); 

				// swap out image and add white border 

				var screen = $("#picScreen").attr("src", url).css({"border-color":"#fff"}); 

			});

			if (studioImagesArray.length < 5) { $("a.prevPage").hide(); $("a.nextPage").hide() };

			$('.scrollable').scrollable({size:4});

			$('#message').fadeIn();

		};

		var moveEnd = GEvent.addListener(map, "moveend", function(){

			changeMessage();

			GEvent.removeListener(moveEnd);

		});

        var bounds = map.getBounds();

        var southWest = bounds.getSouthWest();

        var northEast = bounds.getNorthEast();

        var latSpan = northEast.lat() - southWest.lat();

		var newCenter = marker.getLatLng();

		var newY = newCenter.y + latSpan*0.2;

		var newX = newCenter.x + latSpan*0.2;

		var adjCenter = new GLatLng(newY, newX);

		var checkCenter =  Math.round(map.getCenter().x*1000);

		(checkCenter == Math.round(newX*1000)) ? changeMessage() : map.panTo(adjCenter);

	}

});

