//	*********************************************************************************************		Author
//	*********************************************************************************************		

/*

Title:		ApInit - version NA

Author:		James Hall - www.astonprograms.co.uk

Uses:		ApCore - version 3.0.4

*/

//	*********************************************************************************************		ApSlideShow
//	*********************************************************************************************		

function ApSlideShow_Init(ApSlideShow_Details)
{
	var slideShow = null;
	var widget = document.getElementById(ApSlideShow_Details.widgetID);
	
	if(widget != null)
	{
		slideShow = new ApSlideShow(widget, ApSlideShow_Details.slidesURL);

		if(ApSlideShow_Details.max_fps != undefined)
			slideShow.max_fps = ApSlideShow_Details.max_fps;	

		if(ApSlideShow_Details.pause != undefined)
			slideShow.pause = ApSlideShow_Details.pause;	

		if(ApSlideShow_Details.transition != undefined)
			slideShow.transition = ApSlideShow_Details.transition;					

		if(ApSlideShow_Details.startingSlide != undefined)
			slideShow.startingSlide = ApSlideShow_Details.startingSlide;	
			
		if(ApSlideShow_Details.slideClass != undefined)
			slideShow.slideClass = ApSlideShow_Details.slideClass;				
			
		if(ApSlideShow_Details.slideZIndex != undefined)
			slideShow.slideZIndex = ApSlideShow_Details.slideZIndex;	
		
		if(ApSlideShow_Details.pauseButton_pauseClass != undefined)
			slideShow.pauseButton_pauseClass = ApSlideShow_Details.pauseButton_pauseClass;				
			
		if(ApSlideShow_Details.pauseButton_playClass != undefined)
			slideShow.pauseButton_playClass = ApSlideShow_Details.pauseButton_playClass;
	}	
	
	return slideShow;
}

//	*********************************************************************************************		DDM
//	*********************************************************************************************

function ApDDM_Init(ApDDM_Details)
{
	var menu = null;
	var widget = document.getElementById(ApDDM_Details.widgetID);
	
	if(widget != undefined)
	{
		menu = new ApDDM(widget, ApDDM_Details.offset);
		
		if(ApDDM_Details.collapseDelay != undefined)
			menu.collapseDelay = ApDDM_Details.collapseDelay;			

		if(ApDDM_Details.popupClass != undefined)
			menu.popupClass = ApDDM_Details.popupClass;	

		if(ApDDM_Details.hasChildrenClass != undefined)
			menu.hasChildrenClass = ApDDM_Details.hasChildrenClass;

		if(ApDDM_Details.selectedClass != undefined)
			menu.selectedClass = ApDDM_Details.selectedClass;	

		if(ApDDM_Details.subMenuOffset != undefined)
			menu.subMenuOffset = ApDDM_Details.subMenuOffset;							

		if(ApDDM_Details.parentLink != undefined)
			menu.parentLink = ApDDM_Details.parentLink;					
	}
	
	return menu;
}

//	*********************************************************************************************		
//	*********************************************************************************************

//	*********************************************************************************************		ImportScript

apImportScript = function(url)
{
	scriptObj = document.createElement("script");
	scriptObj.src = url;
	scriptObj.type="text/javascript";
	document.getElementsByTagName("head")[0].appendChild(scriptObj);
}


//	*********************************************************************************************		GoogleAnylitics 

function googleAnylitics()
{	
	/*<JasobNoObfs>*/
	try 
	{  
		var pageTracker = _gat._getTracker("");
		pageTracker._initData();
		pageTracker._trackPageview();
	}
	catch(err) {}
	/*</JasobNoObfs>*/	
	
}

//	*********************************************************************************************		GoogleMaps

function GoogleMap(widget, name, address, alterable)
{
	this.ref = apPersistance.add(this);
	this.name = name;
	this.address = address;

	var latlng = new google.maps.LatLng(51.463274, -0.159115); // Clapham Default
	var myOptions;
	if(alterable)
		myOptions = { zoom: 14, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
	else
		myOptions = { zoom: 14, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true, disableDoubleClickZoom: true, draggable: false, keyboardShortcuts: false, mapTypeControl: false, navigationControl: false, scaleControl: false, scrollwheel: false };
		
	this.map = new google.maps.Map(widget, myOptions);	
		
	var geocoder = geocoder = new google.maps.Geocoder();
	eval("geocoder.geocode({'address': address}, function(results, status){apPersistance.item(" + this.ref + ").setAddress(results, status);});");
}

GoogleMap.prototype.setAddress = function(results, status)
{
	if (status == google.maps.GeocoderStatus.OK) 
	{
		this.map.setCenter(results[0].geometry.location);
		var marker = new google.maps.Marker({ map: this.map,  position: results[0].geometry.location});
	}
	else
	{
		//alert("Geocode of " + this.address + "\nwas not successful for the following reason: " + status);
	}
}

//	*********************************************************************************************		ApInit

function Ap_Init()
{
	/*	***	All Pages	***	*/


	// ApSlideShow
	//var slideShow = ApSlideShow_Init({ widgetID : "slideshow", slidesURL : "/templates/DV8_01/SlideShow_Slides.inc", pause : 7000 });
		
	// ApDDM
	var ddm;
	if(ap.getBrowserType() == "MSIE 6.0")	
		ddm = ApDDM_Init({ widgetID : "ddm", offset: { x : 0, y : 0}, subMenuOffset: { x : 0, y : 0 }, parentLink : "off" });
	else
		ddm = ApDDM_Init({ widgetID : "ddm", offset: { x : -2, y : -40}, subMenuOffset: { x : 0, y : 0 }, parentLink : "off" });
		
	//googleAnylitics();	
	
	/*	***	Specific Pages	***	*/
	
	//gallery
	var thumbnails = document.getElementById("thumbnails");
	if(thumbnails != null)
	{
		new ImageSwap(thumbnails);
	}

}

//	*********************************************************************************************		Execute

/*<JasobNoObfs>*/
//apImportScript("/scripts/cssHax.js");
apImportScript("/scripts/ApCore.js");
apImportScript("/scripts/ApDDM.js");
apImportScript("/scripts/ValidateSubmit.js");
apImportScript("/scripts/ImageSwap.js");
/*
apImportScript("/scripts/ApAsync.js");
apImportScript("/scripts/ApSlideShow.js");
*/
apImportScript("http://www.google-analytics.com/ga.js");

window.onload = function(){setTimeout("Ap_Init()", 100)};

var loginAs = null;









//	*********************************************************************************************		CSS Hax


function Ap_importIECssHax()
{
	var browserType = Ap_getBrowserType();
	
	if(browserType == "MSIE 6")
	{
		Ap_importCSS("/styles/ie6Hax.css");
	}
	if(browserType == "MSIE 7")
	{
		Ap_importCSS("/styles/ie7Hax.css");
	}
	if(browserType == "MSIE 8")
	{
		Ap_importCSS("/styles/ie8Hax.css");
	}	
	if(browserType == "Safari")
	{
		Ap_importCSS("/styles/safariHax.css");
	}		
	/*
	if(browserType == "Opera")
	{
		Ap_importCSS("/styles/operaHax.css");
	}		
	*/
}

function Ap_importCSS(url)
{
	var head = document.getElementsByTagName("head")[0];

	var newStyle = document.createElement("link");
	newStyle.setAttribute("rel","stylesheet");
	newStyle.setAttribute("type", "text/css");
	newStyle.setAttribute("href", url);

	head.appendChild(newStyle);	
}

function Ap_getBrowserType()
{
	if(navigator.userAgent.indexOf("MSIE 6") > -1)
	{
		return "MSIE 6";
	}
	if(navigator.userAgent.indexOf("MSIE 7") > -1)
	{
		return "MSIE 7";
	}		
	if(navigator.userAgent.indexOf("MSIE 8") > -1)
	{
		return "MSIE 8";
	}		
	if(navigator.userAgent.indexOf("Firefox") > -1)
	{
		return "Firefox";
	}	
	if(navigator.userAgent.indexOf("Safari") > -1)
	{
		return "Safari";
	}	
	if(navigator.userAgent.indexOf("Opera") > -1)
	{
		return "Opera";
	}		
	
	return "unknown";
}

Ap_importIECssHax();
