$(document).ready(function(){
  Urbanaction.init();
});

//////////////////
// isClassName //
function isClassName(oNode,sClass) {
	return (" "+oNode.className+" ").indexOf(sClass)!=-1;
}

///////////
// flv  //
/////////
function setSize(sId,iWidth,iHeight) {
	mObj = document.getElementById(sId);
	if (mObj!=null) {
		mObj.style.width = iWidth+"px";
		mObj.style.height = iHeight+"px";
		mEmb = mObj.getElementsByTagName("embed")[0];
		if (mEmb!=null) {
			mEmb.style.width = iWidth+"px";
			mEmb.style.height = iHeight+"px";
		}
	}
	alert("setSize");
}
function addFlv(url,size,loop,target) {
	loop = loop==null?false:loop==1;
	aPth = url.split("/");
	sFle = aPth[aPth.length-1];
	sNme = sFle.split(".")[0];
	sVar = 'id='+sNme+'&size='+size+'&loop='+loop+'&url='+url;
	sSrc = 'wp-content/themes/urbanaction/style/flashvideoplayer.swf?'+sVar;
//	document.write('<object id="'+sNme+'" class="flvswf" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1" height="1" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="'+sSrc+'" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><embed src="'+sSrc+'" quality="high" scale="noscale" salign="lt" width="1" height="1" name="flashvideoplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

	var fo = new SWFObject(sSrc, target, "1", "1", "7", "#FFFFFF");
	fo.addParam("salign", "lt");
	fo.addParam("flashvars", sVar);
	fo.write(target); 

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//var geoXml = new GGeoXml("http://mapgadgets.googlepages.com/cta.kml");
//var geoXml = new GGeoXml("urbanaction.kml");
//var geoXml = new GGeoXml("cta.kml");
//var geoXml = new GGeoXml("NDSM.kml");
//window.open("urbanaction.kml","_blank");

var Urbanaction = new function() {}

Urbanaction.init = function() {
	
//	$("body").append("asdfasdfasdf");
//	$("body").append( $("#page").height() );
//	var iPageH = $("#page").height();
//	$("body").append( $("#page").height() );
//	$("#header").css( {background:"url(header/skaterboy.jpg) 0px 0px"});

	// min-height
	var iWdgH = $("div#sidebar").height()+300;
//	$("body").append(iWdgH+" "+$("div#sidebar").css("top"));
	if ($("#page").height()<iWdgH) $("#page").height(iWdgH);

	// css 1st menu>li
	aMenu = $("ul#menu>li>a");
	$(aMenu[0]).css( {background:"url()",paddingLeft:"0px"});

	// submenu display
	$("ul#menu>li>ul[li.current_page_item]").css( {display:"block"});
	$("ul#menu>li[li.current_page_item]").addClass("current_page_item");
	
//	// #links image bg
//	var aLinks = $("div#sidebar>ul>li.widget_links>ul>li");
//	for (var i=0;i<aLinks.length;i++) {
////		$("body").append("a");
////		$(aLinks[i]).addClass($(aLinks[i]).$("a.html()"));
//		var sText = $(aLinks[i]).children("a").html();
//		var sClassName = sText.toLowerCase().replace(" ", "");
//		for (j=0;j<5;j++) sClassName = sClassName.replace(" ", "");
//		$(aLinks[i]).addClass( sClassName );
//		$(aLinks[i]).children("a").css( {background:"url(contrib/"+sClassName+".png) no-repeat"});
//		$(aLinks[i]).children("a").html("<span>"+sText+"</span>");
////		$("body").append( $(aLinks[i]).children("a").html() );
//	}
////	$("li.widget_links>ul>li>a");
////	$("body").append($("li.widget_links>ul>li>a.html()"));
}
//////////////////
// google maps //
Urbanaction.loadGoogleMaps = function() {
	if (GBrowserIsCompatible()) {
		var mmCenter = new GLatLng(52.38835,4.892617);
		var container = document.getElementById("googlemaps");
		var map = new GMap2(container);

		map.setCenter(mmCenter, 13);
//		map.setCenter(new GLatLng(41.875696,-87.624207), 11); 
		map.addControl(new GSmallMapControl());
//		map.addOverlay(geoXml);
//		
//		directions = new GDirections(map, directionsPanel);
//		directions.load("New York, NY to Chicago, IL");

		$("#googlemaps>div>span").css( {fontFamily:"Verdana, sans-serif",fontSize:"9px",letterSpacing:"-1px"});
		$("#googlemaps>div>a").css( {fontFamily:"Verdana, sans-serif",fontSize:"9px",letterSpacing:"-1px"});

		// urban action
		var mmPoint = new GLatLng(52.40035,4.892617);
		var mmIcon = new GIcon();
		mmIcon.image  = "wp-content/themes/urbanaction/style/gm_icon.png";
		mmIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		mmIcon.iconSize = new GSize(32, 32);
		mmIcon.shadowSize = new GSize(64, 32);
		mmIcon.iconAnchor = new GPoint(16, 32);
		mmIcon.infoWindowAnchor = new GPoint(5, 1);
		var mmMarker = new GMarker(mmPoint, mmIcon);
		GEvent.addListener(mmMarker, "click", function() {
			mmMarker.openInfoWindowHtml("<div style=\"width:200px;font-family:Verdana, san-serif;font-size:10px\"><h3>Urban Action :: NDSM terrein</h3><a target=\"_blank\" href=\"http://maps.google.nl/maps/ms?msa=0&msid=115583994351870215156.0004358a513299501e415&ll=52.390792,4.896212&spn=0.027185,0.062742&z=14&om=1\">Klik hier voor een persoonlijk routeplan per auto.</a></div>");
		});
		map.addOverlay(mmMarker);

		// ns
		var nsIcon = new GIcon();
		nsIcon.image  = "wp-content/themes/urbanaction/style/ns_icon.png";
		nsIcon.iconSize = new GSize(32, 32);
		nsIcon.iconAnchor = new GPoint(16, 16);
		nsIcon.shadow = "wp-content/themes/urbanaction/style/ns_icon_shadow.png";
		nsIcon.shadowSize = new GSize(32, 32);
		nsIcon.infoWindowAnchor = new GPoint(16, 16);
		var nsPoint = new GLatLng(52.380302,4.900761);
		var nsMarker = new GMarker(nsPoint, nsIcon);
		GEvent.addListener(nsMarker, "click", function() {
			nsMarker.openInfoWindowHtml("<div style=\"width:170px;font-family:Verdana, san-serif;font-size:10px\"><h3>Amsterdam Centraal Station</h3><a target=\"_blank\" href=\"http://www.ns.nl\">Klik hier voor de NS reisplanner.</a></div>");
		});
		map.addOverlay(nsMarker);

		// pond
		var polyline = new GPolyline([
			new GLatLng(52.380890, 4.89947),
			new GLatLng(52.384029, 4.89689),
			new GLatLng(52.390739, 4.894409),
			new GLatLng(52.3965  , 4.888573),
			new GLatLng(52.401016, 4.891641)
		], "#444488", 2);
		map.addOverlay(polyline);

		// festival terrein
		var polygon = new GPolygon([
			new GLatLng(52.402184,4.894785),
			new GLatLng(52.401581,4.894087),
			new GLatLng(52.401352,4.894559),
			new GLatLng(52.401096,4.894645),
			new GLatLng(52.400814,4.894527),
			new GLatLng(52.400482,4.894141),
			new GLatLng(52.400311,4.894516),
			new GLatLng(52.399773,4.894313),
			new GLatLng(52.399460,4.896448),
			new GLatLng(52.400372,4.896834),
			new GLatLng(52.400906,4.897521),
			new GLatLng(52.402184,4.894785)
		], "#AA2200", 1, 1, "#FF6600", 1);
		map.addOverlay(polygon)



	}
}

//	$(aMenu[0]).css("background","url()");
//	$(aMenu[0]).css("padding-left","0px");
//	$(aMenu[0]).css({ paddingLeft: "0px" });
//	$(oDiv).css("background-image",sNurl);
//	var oFirstLi = $("ul#menu>li[0]");
//	oFirstLi.css({ paddingLeft: "0px" });
//	oFirstLi.css({ background: "" });
	//
//	if (bForum==null) bForum = false;
//	if (!bForum) {
//		var fo = new FlashObject(sUrl,sSwfId,760,160,"8.0.0","#ffffff",true,"high");
//		fo.addParam("allowScriptAccess", "always");
//		fo.addParam("menu", "false");
//		bSwf = fo.write(sHolder);//false;//
//		if (bSwf) {
//			mSwf = $("#"+sSwfId);
//		} else {
//		}
//	}
	//
//	Urbanaction.setupMenu();
//	$("iframe").load( function() {
//		$(window).resize( function() {
//			$("iframe").height(window.innerHeight-180);
//		});
//		$("iframe").height(window.innerHeight-180);
//	});
//	$(window).resize();
//	$("#output").append("<br/>________<br/>");

//Urbanaction.setupMenu = function() {
//	// swap last five li's for right floating (lang)
//	var oLastLi = $("ul#menu>li#p11");
//	oLastLi.after($("ul#menu>li#p7"));
//	oLastLi.after($("ul#menu>li#p8"));
//	oLastLi.after($("ul#menu>li#p9"));
//	oLastLi.after($("ul#menu>li#p10"));
//	//var oLastLi = $("ul#menu>li#contact");
//	//oLastLi.after($("ul#menu>li#news"));
//	//oLastLi.after($("ul#menu>li#forum"));
//	//oLastLi.after($("ul#menu>li#fun"));
//	//oLastLi.after($("ul#menu>li#country"));
//	
//	// add events
//	var aLi = $("ul#menu>li").bind("mouseover",function(){
//		if (bSwf) mSwf.get(0).toFlash_roll(this.id,true,true);
//		$("#"+this.id+" > ul").show();//.slideDown("fast");
//		$("#"+this.id).addClass("hover");
//		//$("#content").append("_in: "+this.id+"<br/>");
//	});
//	var aLi = $("ul#menu>li").bind("mouseout", function(){
//		if (bSwf) mSwf.get(0).toFlash_roll(this.id,false,true);
//		$("#"+this.id+">ul").hide();//.slideUp("fast");
//		$("#"+this.id).removeClass("hover");
//		//$("#content").append("_out: "+this.id+"<br/>");
//	});
//}

//Urbanaction.toHTML_roll = function(sId,bOver) {
//	if (bOver) {
//		$("#"+sId+">ul").show();
//		$("#"+sId).addClass("hover");
//		//$("#content").append("=in: "+sId+"<br/>");
//	} else {
//		$("#"+sId+">ul").hide();
//		$("#"+sId).removeClass("hover");
//		//$("#content").append("=out: "+sId+"<br/>");
//	}
//}

//Urbanaction.toHTML_click = function(sId) {
//	window.location.href = $("#"+sId+">a").attr("href");
//}
