/* ====================================================
Show/Hide Product Menu
==================================================== */

function posTop(stTop,enTop){ 

var Tid="submenu";
var topStart = stTop;
var topEnd = enTop;
var millisec = 1000;

var speed = Math.round(millisec / 100); 
var timer = 10; 

     if(topStart > topEnd) { 
         for(i = topStart; i >= topEnd; i--) { 
             setTimeout("changeposTop(" + i + ",'" + Tid + "')",(timer * speed)); 
             timer++; 
         } 
     } else if(topStart < topEnd) { 
         for(i = topStart; i <= topEnd; i++) 
             { 
             setTimeout("changeposTop(" + i + ",'" + Tid + "')",(timer * speed)); 
             timer++; 
         } 
     } 
 }
 
 function changeposTop(itop, Tid) { 
     document.getElementById(Tid).style.top = itop+"px"; 
}


function showprods() {
	if (document.getElementById("submenu").style.top=="160px") 
	{
	document.getElementById("submenu").style.display="block";
	posTop(160,160);
	document.getElementById("hdmenu").style.display = "inline";
	}
	else if (document.getElementById("submenu").style.top="129px") 
	{
	document.getElementById("submenu").style.display="block";
	document.getElementById("tmcover").style.display="block";
	posTop(129,160);
	document.getElementById("hdmenu").style.display = "inline";
	}
return false;
}

function hideprods() {
	if (document.getElementById("submenu").style.top=="160px") 
	{
	posTop(160,129);
	setTimeout("document.getElementById('submenu').style.display='none';", 1000);
	document.getElementById("hdmenu").style.display = "none";
	document.getElementById("tmcover").style.display="none";
	return true;
	}
}


function contactUs(){

	top.location = 'mailto:info@sheffieldblinds.co.uk';
}


/* ====================================================
Product - Blinds content swap
==================================================== */

function swapcontentb(d) {

	var theimg = "/gfx/photos/blinds_"+d+".jpg";
	var imgs = document.getElementsByTagName("img");  

	for (var i=0; i<imgs.length; i++) 
	{   
		var imge = imgs[i];  
		thisSRC = imge.getAttribute("src");  
		thisREL = imge.getAttribute("rel"); 
		
		if(thisSRC && (thisREL == "csimg"))
		{  
		imge.setAttribute("src",theimg);
		} 
	} 


	if (document.getElementById('bcontent').style.display = "block")
	{
	document.getElementById('bmenu').style.display = "none";
	document.getElementById('bcontent').innerHTML = document.getElementById(d).innerHTML;
	}
return true;
}

 /* ====================================================
 Image Slide Show
==================================================== */

//*** Fader script ***
// http://brainerror.net/scripts/javascript/blendtrans/ for the fade transition

function opacityin(id, opacStart, opacEnd, millisec) { 
//speed for each frame 
var speed = Math.round(millisec / 100); 
var timer = 10; 

//determine the direction for the blending, if start and end are the same nothing happens 
if(opacStart > opacEnd) { 
 for(i = opacStart; i >= opacEnd; i--) { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} else if(opacStart < opacEnd) { 
 for(i = opacStart; i <= opacEnd; i++) 
 { 
     setTimeout("changeOpacin(" + i + ",'" + id + "')",(timer * speed)); 
     timer++; 
 } 
} 
} 

//change the opacity for different browsers 
function changeOpacin(opacity, id) { 
var object = document.getElementById(id).style; 
	object.filter = "alpha(opacity=" + opacity + ")"; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
} 


function slidePhoto(id, opacStart, opacEnd, millisec) { 
//speed for each frame 
var speed = Math.round(millisec / 100); 
var timer = 10; 

	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) 
	{ 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("slidePhotoAction(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
	else if(opacStart < opacEnd) 
	{ 
		for(i = opacStart; i <= opacEnd; i++) 
		{ 
			setTimeout("slidePhotoAction(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
}

function slidePhotoAction(pos,id) { 

	document.getElementById(id).style.left = pos+"px"; 
}

function contentLoading()
{
	if(document.getElementById("rightphotos"))
	{
		pLoad = document.getElementById("rightphotos");
		dLoad = document.createElement("div");
		pLoad.appendChild(dLoad);
		dLoad.setAttribute("id","loading");
	}
}



//*** DECLARE VARIABLES ***
var imgwidth = "403";
var imgheight = "380";
var imgalt = "Bespoke Blinds &amp; Poles Photography";
var imgclass = "rsimg";

//*** image array moved to individual pages for multiple galleries.

//*** Image swaper ***
function imagehide() {

	//this hides the initial fade-in image to make way for the full slide-show 	
	document.getElementById("imageslide").style.display = "none";

}

function imagegallery() {

	if (nimg<opimages.length-1)
	{
	nimg++
	}
	else if (nimg>=opimages.length-1)
	{
	nimg = 0;
	}
	
	document.getElementById("image_gallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimg]+'" border="0" width="'+imgwidth+'" height="'+imgheight+'" alt="'+imgalt+'" class="'+imgclass+'" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);  
	return true;
}

//****** Image Gallery - image change *******

function image_swap(nimg)
{
	/*
	//this part has been added to show the last image in the array to start with for 5 seconds as the slideshow has a 5 second delay	
	document.getElementById("image_gallery").innerHTML = '<div id="slidecontainer" class="imagefade"><img src="'+opimages[nimgl]+'" border="0"  id="imageslide" alt="D&amp;M Business Cards" /></div>';
	opacityin('slidecontainer', 0, 100, 500);
	setTimeout("opacityin('slidecontainer', 100, 0, 500)",4400);
	var Tout = setTimeout("imagehide()", 4800);

	//this part activates and loops the fade in/out and image change script	
	var Tinterval = setInterval("imagegallery()", 5000);
	*/
	
	galleryimgs = document.getElementById("rightphotos").getElementsByTagName("img");
	totalimgs = galleryimgs.length;
	
	if(nimg == totalimgs-1)
	{
		fimg = 0;
		
		if(totalimgs>2)
		{
			bimg = totalimgs-2;
		}
		else
		{
			bimg = 0;
		}
	}
	else
	{
		fimg = nimg+1;
		
		if(nimg == 0)
		{
			bimg = totalimgs-1;
		}
		else
		{
			bimg = nimg-1;
		}
	}
	
	for(i=0;i<totalimgs;i++)
	{
		zID = "img"+i;
		
		galleryimgs[i].setAttribute("id",zID);
		document.getElementById(zID).style.zIndex = 10;
	}
	
	id = "img"+nimg;
	ido = "img"+bimg;
	document.getElementById(id).style.zIndex = 15;
	slidePhoto(id, 419, 0, 300);
	slidePhoto(ido, 0, -419, 300);
	
	bimgid = "img"+bimg;
	if(document.getElementById(bimgid))
	{
		var ToutB = setTimeout("document.getElementById('"+bimgid+"').style.left = '419px'", 3000);
	}
	
	var Tout = setTimeout("image_swap(fimg)", 6000);
}

function image_swap_ti(nimg)
{
	galleryimgs = document.getElementById("rightphotos").getElementsByTagName("img");
	totalimgs = galleryimgs.length;
	
	if(nimg == totalimgs-1)
	{
		fimg = 0;
		
		if(totalimgs>2)
		{
			bimg = totalimgs-2;
		}
		else
		{
			bimg = 0;
		}
	}
	else
	{
		fimg = nimg+1;
		
		if(nimg == 0)
		{
			bimg = totalimgs-1;
		}
		else
		{
			bimg = nimg-1;
		}
	}
	
	for(i=0;i<totalimgs;i++)
	{
		zID = "img"+i;
		
		galleryimgs[i].setAttribute("id",zID);
		document.getElementById(zID).style.zIndex = 10;
	}
	
	id = "img"+nimg;
	ido = "img"+bimg;
	document.getElementById(id).style.zIndex = 15;
	slidePhoto(id, 200, 0, 300);
	slidePhoto(ido, 0, -200, 300);
	
	bimgid = "img"+bimg;
	if(document.getElementById(bimgid))
	{
		var ToutB = setTimeout("document.getElementById('"+bimgid+"').style.left = '200px'", 3000);
	}
	
	var Tout = setTimeout("image_swap_ti(fimg)", 6000);
}
 

var ophead = new Array();
ophead[0]='/gfx/home_special_offers.png';
ophead[1]='/gfx/home_special_offers2.png';


 //*** Head Banner ***
 function headgallery() {
 
 	if (nimg<ophead.length-1)
 	{
 	nimg++
 	}
 	else if (nimg>=ophead.length-1)
 	{
 	nimg = 0;
 	}
 	
 	document.getElementById("head_gallery").innerHTML = '<div id="slidecontainerH" class="imagefade"><img src="'+ophead[nimg]+'" width="370" height="110" alt="In Store Special Offers - Click Here" /></div>';
 	opacityin('slidecontainerH', 1000, 0, 300);
 	setTimeout("opacityin('slidecontainerH', 0, 100, 300)",5600);  
 	return true;
}



function showroomMap(map){

	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Your browser does not support XMLHTTP!");
	}
	
	if(map == "hillsborough")
	{
		thisMap = "hillsborough";
	}
	else
	{
		thisMap = "beauchief";
	}

	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{
			document.getElementById("googlemap").innerHTML= '';	
			document.getElementById("googlemap").innerHTML=xmlhttp.responseText;
		}
	}
	
	var whichMap = "/get_map.php?map="+thisMap;
	xmlhttp.open("GET",whichMap,true);
	xmlhttp.send(null);

}


/* ====================================================
 popup box
==================================================== */
 
function infoPop(event,idiv) {

//Need to define the width and height of the popup to stop popup from going out of screen view
popupWidth = 520; //add 32px onto width value to account for scroll bars
popupHeight = 285;


x = event.clientX+document.documentElement.scrollLeft;
y = event.clientY+document.documentElement.scrollTop;
xfind = screen.availWidth+document.documentElement.scrollLeft-popupWidth;
yfind = screen.availHeight+document.documentElement.scrollTop-popupHeight;

	if (x >= xfind && y >= yfind)
	{
	ax = x - popupWidth;
	ay = y - popupHeight;
	document.getElementById(idiv).style.left = ax+"px";
	document.getElementById(idiv).style.top = ay+"px";
	document.getElementById(idiv).style.display = "block";
	}
	else if (x >= xfind)
	{
	bx = x - popupWidth;
	by = y;
	document.getElementById(idiv).style.left = bx+"px";
	document.getElementById(idiv).style.top = by+"px";
	document.getElementById(idiv).style.display = "block";
	}
	else if (y >= yfind)
	{
	cx = x;
	cy = y - popupHeight;
	document.getElementById(idiv).style.left = cx+"px";
	document.getElementById(idiv).style.top = cy+"px";
	document.getElementById(idiv).style.display = "block";
	}
	else
	{
	document.getElementById(idiv).style.left = x+"px";
	document.getElementById(idiv).style.top = y+"px";
	document.getElementById(idiv).style.display = "block";
	}
}


function closeit(idiv)
{
document.getElementById(idiv).style.display = "none";
}


/* ====================================================
Blog - redirect
==================================================== */

function show_blog() {

setTimeout("show_blogt()",5000);

}


function show_blogt() {

top.location = "http://bespokeblindsandpoles.blogspot.com";

}

function changebar(){

	document.getElementById("footer").style.position = "relative";
	document.getElementById("footer").style.top = "0px";
	document.getElementById("footer").style.left = "0px";

}


window.onload = function(){contentLoading();}