/**
 * @author Ellier
 */

 var cssNode; // To load CSS links on the fly
 var scriptNode; // To load scripts links on the fly
 var isThereSlideShow = false;
 
function loadPage(doc,page) {

	var content = document.getElementById("content"); 
	if(content.hasChildNodes() ) {
		var t = new OpacityTween(content,Tween.regularEaseIn,100,0,0.5);
		t.start(); 
		t.onMotionFinished = function()	{
		    while ( content.childNodes.length >= 1 ) {
		        content.removeChild( content.firstChild ); 
		    	}
				
				if(isThereSlideShow == true) {
					clearInterval(slideShowTimer);
					slideShowTimer = null;
					clearInterval(slideShowTimer2);
					slideShowTimer = null;
					isThereSlideShow = false;
				}

			 	getData(doc,page,'responseText');
			}
	} else {
	 	alert("An errror has ocurred, please reload this page");		
	}
}

 
function setContent() { 
		var content = document.getElementById("content");
		content.innerHTML = xmldata;
		var t = new OpacityTween(content,Tween.regularEaseIn,0,100,0.5);
		t.start();
}

function homePage() {
	removeScript()
	removeCSS();
	insertCSS('home.css');
	insertScript('scripts/slideshow.js');
//	getData('images/gallery/home/gallery.xml', setGallery, 'responseXML');
	setContent();
	
	if(isThereSlideShow == false) getData("images/gallery/home/models/home-slideshow.xml", initSlide);
	isThereSlideShow = true;
}

function bioPage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('bioIE.css') : insertCSS('bio.css'); // Alternative css to fix IE problems
	insertScript('scripts/dummy.js')
	setContent();
}

function pasPage() {
	removeScript()
	removeCSS();
	insertCSS('pas.css');
	insertScript('scripts/slideshow.js');
	setContent();
			
	if(isThereSlideShow == false) getData("images/events/events-slideshow.xml", initSlide);
	isThereSlideShow = true;
}

function rationalPage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('bioIE.css') : insertCSS('bio.css'); // Alternative css to fix IE problems
	insertScript('scripts/dummy.js')
	setContent();
}

function dressShirts() {
	removeScript()
	removeCSS();
	insertCSS('home.css');
	insertScript('scripts/dummy.js');
	getData('images/gallery/dressShirts/gallery.xml', setGallery, 'responseXML');
	setContent();
}

function tailoredPage() {
	removeScript()
	removeCSS();
	insertCSS('home.css');
	insertScript('scripts/dummy.js');
	getData('images/gallery/suits/gallery.xml', setGallery, 'responseXML');
	setContent();
}

function leathers() {
	removeScript()
	removeCSS();
	insertCSS('home.css');
	insertScript('scripts/dummy.js');
	getData('images/gallery/leather/gallery.xml', setGallery, 'responseXML');
	setContent();
}

function accessoriesPage() {
	removeScript()
	removeCSS();
	insertCSS('home.css');
	insertScript('scripts/dummy.js');
	getData('images/gallery/accessories/gallery.xml', setGallery, 'responseXML');
	setContent();
}

function certificatePage(){
	removeScript()
	removeCSS();
	insertCSS('certificate.css');
	insertScript('scripts/dummy.js');
	setContent();	
}

function vaccPage(){
	removeScript()
	removeCSS();
	insertCSS('vacc.css');
	insertScript('scripts/dummy.js');
	setContent();	
}

function tradeshowsPage(){
	removeScript()
	removeCSS();
	insertCSS('tradeshows.css');
	insertScript('scripts/dummy.js');
	setContent();	
}

function salesPage() {
	removeScript()
	removeCSS();
	insertCSS('sales.css');
	insertScript('scripts/contact-form.js');
	setContent();
}

function pressPage() {
	removeScript()
	removeCSS();
	insertCSS('press.css');
	insertScript('scripts/dpContentBckDrop.js');
	setContent();
}

function tvPage() {
	removeScript()
	removeCSS();
	insertCSS('tv.css');
	insertScript('scripts/dpContentBckDrop.js');
	setContent();
}

function flagshipStorePage() {
	removeScript()
	removeCSS();
	insertCSS('flagshipStore.css');
	insertScript('scripts/dummy.js');
	setContent();
}

function designPage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('manufactureIE.css') : insertCSS('manufacture.css');
	insertScript('scripts/slideshow.js');
	setContent();

	if(isThereSlideShow == false) getData("images/design/design-slideshow.xml", initSlide);
	isThereSlideShow = true;
}
	
function manufacturePage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('manufactureIE.css') : insertCSS('manufacture.css');
	insertScript('scripts/slideshow.js');
	setContent();
			
	if(isThereSlideShow == false) getData("images/factory/manufacture-slideshow.xml", initSlide);
	isThereSlideShow = true;
}

function manufactureShirtPage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('manufactureIE.css') : insertCSS('manufacture.css');
	insertScript('scripts/slideshow.js');
	setContent();
			
	if(isThereSlideShow == false) getData("images/factoryShirt/manufacture-slideshow.xml", initSlide);
	isThereSlideShow = true;
}

function instorePage() {
	removeScript()
	removeCSS();
	(document.all) ? insertCSS('manufactureIE.css') : insertCSS('manufacture.css');
	insertScript('scripts/slideshow.js');
	setContent();

	if(isThereSlideShow == false) getData("images/instore/instore-slideshow.xml", initSlide);
	isThereSlideShow = true;
}

function underPage() {
	removeScript()
	removeCSS();
	insertCSS('press.css');
	insertScript('scripts/dummy.js');
	setContent();
}

/********** Insert Content *********/

function insertCSS(cssLink) {
	var headID = document.getElementsByTagName("head")[0];         
	cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.rel = 'stylesheet';
	cssNode.href = 'CSS/' + cssLink;
	cssNode.media = 'screen';
	headID.appendChild(cssNode);
}

function removeCSS(){
	if(cssNode){
	var headID = document.getElementsByTagName("head")[0];
	headID.removeChild(cssNode);
	}
}

function insertScript(scriptLink) {
	var headID = document.getElementsByTagName("head")[0];         
	scriptNode = document.createElement('script');
	scriptNode.type = 'text/javascript';
	scriptNode.src = scriptLink;
	headID.appendChild(scriptNode);
}

function removeScript(){
	if(scriptNode){
	var headID = document.getElementsByTagName("head")[0];
	headID.removeChild(scriptNode);
	}
}
/*

// Creates a backdrop div for dynamic content with a translucent div in  it for effect
function bckDropForContent(objParent,Opacity,Color,Width,Height) {
	(!Opacity) ? this.O = '0.7' : this.O = Opacity;
	(!Color) ? this.C = '#000' : this.C = Color;
	(!Width) ? this.W = '100%' : this.W = Width;
	(!Height) ? this.H = '100%' : this.H = Height;
	
	this.bckDrop = document.createElement('div');
	this.bckDropTrans = document.createElement('div');
	this.bckDrop.style.position = 'absolute';
	this.bckDropTrans.style.position = 'absolute';
	this.bckDropTrans.style.floatCSS = 'left';
	
	this.bckDrop.style.width = this.W;
	this.bckDropTrans.style.width = '100%';
	this.bckDrop.style.height = this.H;
	this.bckDropTrans.style.height = '100%';
	this.bckDropTrans.style.backgroundColor = this.C;
	this.bckDropTrans.style.opacity = this.O;
	if(document.all){
		this.bckDrop.style.left = 0;
		this.bckDropTrans.style.left = 0;
		this.bckDrop.style.styleFloat = 'left';  // Explorer is a piece of shit
		this.bckDropTrans.style.styleFloat = 'left';  // Explorer is a piece of shit
		var op = Opacity * 100;
		this.bckDrop.style.filter = "Alpha(opacity=100)";
		this.bckDropTrans.style.filter = "Alpha(opacity=" + op + ")";

	}
	
	(!objParent) ? this.parent = document.getElementsByTagName('body')[0] : this.parent = document.getElementById(objParent);
	this.bckDrop.appendChild(this.bckDropTrans);
	this.parent.appendChild(this.bckDrop);
}

function showContWBkg() {
	var newBckDrop = new bckDropForContent('printContent','0.8','#382a37','847px','550px');
	newBckDrop.bckDrop.setAttribute('id','backDrop');
	var obj = document.getElementById('backDrop');

	var newsHolder = document.createElement('div');
	newsHolder.style.position = 'absolute';
	newsHolder.setAttribute('id','newsHolder');
	newsHolder.style.display = 'none';
	newsHolder.innerHTML = xmldata;
	document.getElementById('printContent').appendChild(newsHolder);

	newBckDrop.bckDrop.onclick = function(){
		var obj2 = document.getElementById('newsHolder');
		obj.parentNode.removeChild(obj2);
		var t2 = new OpacityTween(obj,Tween.strongEaseOut,90,0,1);
		t2.start();
		t2.onMotionFinished = function(){
			obj.parentNode.removeChild(obj);
		};
	};

	var t1 = new OpacityTween(document.getElementById('backDrop'),Tween.strongEaseOut,20,90,1);
	t1.start();
	t1.onMotionFinished = function(){
		newsHolder.style.display = 'block';
	}

}

*/
// New functions to get press releases

function getPress () {
	showPress();
}

var expandedPress=null;
var pressrelDiv;
var theDiv;

function showPress() {
	pressrelDiv = document.createElement('div');
//	pressrelDiv.innerHTML = xmldata;
	pressrelDiv.style.position = 'absolute';
	pressrelDiv.style.width = '100%';
	pressrelDiv.style.height = '100%';
	pressrelDiv.style.opacity = 0;
	pressrelDiv.style.backgroundColor = "#382a32";
	pressrelDiv.style.display = "block";
	pressrelDiv.style.top = 0;
	pressrelDiv.style.left = 0;
	
	theDiv = document.createElement('div');
	theDiv.setAttribute('id','theDiv');
	theDiv.innerHTML = xmldata;
	theDiv.style.backgroundColor = "#382a32";
	
	if(document.all) {
		pressrelDiv.style.filter = "Alpha(opacity=100)";
	}
	document.getElementById('printContent').appendChild(pressrelDiv);
	pressrelDiv.appendChild(theDiv);
	var t1 = new OpacityTween(pressrelDiv,Tween.strongEaseIn,0,100,1);
	t1.start();
}

function hidePress() {
	var t1 = new OpacityTween(pressrelDiv,Tween.strongEaseIn,100,0,1);
	t1.onMotionFinished = function(){
		document.getElementById("printContent").removeChild(pressrelDiv);
	}
	t1.start();
}


function hideDiv() {
	var opac = pressrelDiv.style.opacity;
	pressrelDiv.style.opacity = parseFloat(opac) - inc;		
		if(opac==0) {
		clearInterval(interv);
		document.getElementById("rightcolpress").removeChild(pressrelDiv);
		}
}
