/*
	Scripts used for this theme.
	This file Requires jQuery to opperate.
*/

$(document).ready(function() {
	// Updates last link in header
	$("#headlinks li:last").addClass("last");

	// Add On-Click to Top Bar
	$("#locationSwitch a").click(function(){
		// Show Top Panel
		$("#topPanel").slideDown(1000, 'easeOutElastic');
		//$("#locationSwitch").animate({ top: 222 }, { duration: 1000, easing: 'easeOutElastic'});
		
		// Show This's Content
		$("#topPanel .innerPanel div").hide();
		var thisd = $(this).attr('id');
		$("#topPanel #" + thisd).fadeIn();
		
		// Toggle Class on Tab
		$("#locationSwitch a").removeClass("active");
		$(this).addClass("active");		
		
		return false;
	});

	$("#closePanel").click(function(){ 
		$("#topPanel").slideUp(1000, 'easeInElastic'); 
		//$("#locationSwitch").animate({ top: -20 }, { duration: 1000, easing: 'easeInElastic'});
		$("#locationSwitch a").removeClass("active");	
	});
	
	// Fancy Box Add
	$("img.size-medium").parent().fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	200, 
		'speedOut'		:	300, 
		'overlayShow'	:	true
	});
	

});


// JS Map
var MeOnTheMap=function(options){this.options={address:"",container:"",defaultUI:true,noDragging:false,html:"",zoomLevel:16,view:0};this.preloads=[];this.initialize=function(options){for(var opt in options){this.options[opt]=options[opt];}
this.preparePreloading();this.container=document.getElementById(this.options.container);if(!this.container){alert("Could not locate \""+this.options.container+"\"");return;}
this.findLocation();};this.preparePreloading=function(){var regxp=new RegExp('(src)=("[^"]*")','g');var sources=this.options.html.match(regxp);if(!sources)
return;function getHandler(obj){return function(){var el=document.getElementById(obj.id);if(el){el.parentNode.replaceChild(this,el);obj.marker.tooltip.redraw(true);}};};for(var i=0;i<sources.length;i++){this.options.html=this.options.html.replace(sources[i],"style=\"visibility:visible\" id=\"preloadimg"+i+"\" src=\"\"");var src=sources[0].split("=\"")[1];src=src.substring(0,src.length-1);var img=new Image();this.preloads.push({element:img,src:src,id:"preloadimg"+i});img.onload=getHandler(this.preloads[this.preloads.length-1]);}};this.startPreloading=function(marker,map){for(var i=0;i<this.preloads.length;i++){this.preloads[i].marker=marker;this.preloads[i].map=map;this.preloads[i].element.src=this.preloads[i].src;}};this.findLocation=function(){var _this=this;this.geoLocator=new GClientGeocoder();this.geoLocator.getLatLng(this.options.address,function(response){_this.handleGetLocatorResponse(response);});};this.getIcon=function(){var icon=new GIcon(G_DEFAULT_ICON);icon.image="images/icon.png";icon.shadow="images/shadow.png";icon.iconSize=new GSize(35,35);icon.shadowSize=new GSize(52,35);icon.iconAnchor=new GPoint(17,35);return icon;};this.handleGetLocatorResponse=function(response){this.geoLocator=null;if(!response){alert("Could not resolve this addess \""+this.options.address+"\"");return;}
var type="";switch(this.options.view){case 1:type=G_SATELLITE_MAP;break;case 2:type=G_HYBRID_MAP;break;default:type=G_NORMAL_MAP;break;}
this.map=new GMap2(this.container);this.map.setMapType(type);this.map.setCenter(response,this.options.zoomLevel);this.map.disableScrollWheelZoom();if(this.options.noDragging)
this.map.disableDragging();if(this.options.defaultUI)
this.map.setUIToDefault();this.marker=new GMarker(response,{icon:this.getIcon()});this.map.addOverlay(this.marker);if(!this.options.html||this.options.html=="")
return;this.marker.tooltip=new Tooltip(this.marker,this.options.html);this.map.addOverlay(this.marker.tooltip);this.marker.tooltip.show();if(this.newCenter){var markerPos=this.map.fromLatLngToDivPixel(this.marker.getPoint());var pos=this.map.fromContainerPixelToLatLng({x:markerPos.x+this.newCenter.x,y:markerPos.y+this.newCenter.y});this.map.setCenter(pos);}
this.startPreloading(this.marker,this.map);};this.adjustMapCenter=function(position){if(!this.geoLocator&&this.map){var markerPos=this.map.fromLatLngToDivPixel(this.marker.getPoint());var pos=this.map.fromContainerPixelToLatLng({x:markerPos.x+position.x,y:markerPos.y+position.y});this.map.setCenter(pos);}else{this.newCenter=position;}};this.initialize(options);};function Tooltip(marker,text){this.isIE6=function(){if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){var ieversion=new Number(RegExp.$1);return(ieversion==6);}
return false;};this.initialize=function(map){this.map=map;this.div=document.createElement("div");var top=document.createElement("div");top.className="top"+((this.isIE6())?" IE6":"");var middle=document.createElement("div");middle.className="middle"+((this.isIE6())?" MIDDLEIE6":"");var bottom=document.createElement("div");bottom.className="bottom"+((this.isIE6())?" BOTTOMIE6":"");middle.innerHTML=text;this.div.appendChild(top);this.div.appendChild(middle);this.div.appendChild(bottom);this.div.className='tooltip';this.div.style.position='absolute';this.div.style.visibility='hidden';map.getPane(G_MAP_FLOAT_PANE).appendChild(this.div);};this.remove=function(){this.div.parentNode.removeChild(this.div);};this.copy=function(){return new Tooltip(this.marker,this.text,this.padding);};this.redraw=function(force){if(!force)
return;var markerPos=this.map.fromLatLngToDivPixel(this.marker.getPoint());var iconAnchor=this.marker.getIcon().iconAnchor;var xPos=(markerPos.x-(this.div.offsetWidth/2));var yPos=markerPos.y-iconAnchor.y-this.div.offsetHeight;this.div.style.top=yPos+'px';this.div.style.left=xPos+'px';};this.show=function(){this.div.style.visibility='visible';};this.hide=function(){this.div.style.visibility='hidden';};this.marker=marker;this.text=text;this.prototype=new GOverlay();};


// jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/

jQuery.easing['jswing']=jQuery.easing['swing'];jQuery.extend(jQuery.easing,{def:'easeOutQuad',swing:function(x,t,b,c,d){return jQuery.easing[jQuery.easing.def](x,t,b,c,d);},easeInQuad:function(x,t,b,c,d){return c*(t/=d)*t+b;},easeOutQuad:function(x,t,b,c,d){return-c*(t/=d)*(t-2)+b;},easeInOutQuad:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t+b;return-c/2*((--t)*(t-2)-1)+b;},easeInCubic:function(x,t,b,c,d){return c*(t/=d)*t*t+b;},easeOutCubic:function(x,t,b,c,d){return c*((t=t/d-1)*t*t+1)+b;},easeInOutCubic:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b;},easeInQuart:function(x,t,b,c,d){return c*(t/=d)*t*t*t+b;},easeOutQuart:function(x,t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b;},easeInOutQuart:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t+b;return-c/2*((t-=2)*t*t*t-2)+b;},easeInQuint:function(x,t,b,c,d){return c*(t/=d)*t*t*t*t+b;},easeOutQuint:function(x,t,b,c,d){return c*((t=t/d-1)*t*t*t*t+1)+b;},easeInOutQuint:function(x,t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t*t*t+b;return c/2*((t-=2)*t*t*t*t+2)+b;},easeInSine:function(x,t,b,c,d){return-c*Math.cos(t/d*(Math.PI/2))+c+b;},easeOutSine:function(x,t,b,c,d){return c*Math.sin(t/d*(Math.PI/2))+b;},easeInOutSine:function(x,t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b;},easeInExpo:function(x,t,b,c,d){return(t==0)?b:c*Math.pow(2,10*(t/d-1))+b;},easeOutExpo:function(x,t,b,c,d){return(t==d)?b+c:c*(-Math.pow(2,-10*t/d)+1)+b;},easeInOutExpo:function(x,t,b,c,d){if(t==0)return b;if(t==d)return b+c;if((t/=d/2)<1)return c/2*Math.pow(2,10*(t-1))+b;return c/2*(-Math.pow(2,-10*--t)+2)+b;},easeInCirc:function(x,t,b,c,d){return-c*(Math.sqrt(1-(t/=d)*t)-1)+b;},easeOutCirc:function(x,t,b,c,d){return c*Math.sqrt(1-(t=t/d-1)*t)+b;},easeInOutCirc:function(x,t,b,c,d){if((t/=d/2)<1)return-c/2*(Math.sqrt(1-t*t)-1)+b;return c/2*(Math.sqrt(1-(t-=2)*t)+1)+b;},easeInElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;},easeOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b;},easeInOutElastic:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4;}
else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b;},easeInBack:function(x,t,b,c,d,s){if(s==undefined)s=0.6;return c*(t/=d)*t*((s+1)*t-s)+b;},easeOutBack:function(x,t,b,c,d,s){if(s==undefined)s=0.6;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b;},easeInOutBack:function(x,t,b,c,d,s){if(s==undefined)s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b;},easeInBounce:function(x,t,b,c,d){return c-jQuery.easing.easeOutBounce(x,d-t,0,c,d)+b;},easeOutBounce:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b;}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;}},easeInOutBounce:function(x,t,b,c,d){if(t<d/2)return jQuery.easing.easeInBounce(x,t*2,0,c,d)*.5+b;return jQuery.easing.easeOutBounce(x,t*2-d,0,c,d)*.5+c*.5+b;}});
