// Controls the rollover states for input buttons and submits

window.onload = function()
{
	//button_elements();
	img_border();
	hr_thickness();
}

function img_border()
{
	var IMGList = document.getElementsByTagName('img');
	
	for (var i = 0; i < IMGList.length; i++)
	{
		IMGList[i].border = '0';
	}
}

function hr_thickness()
{
	var HRList = document.getElementsByTagName('hr');
	
	for (var i = 0; i < HRList.length; i++)
	{
		HRList[i].size = '1';
		HRList[i].color = 'black';
	}
}

function button_elements()
{
	var InputList = document.getElementsByTagName('input');
	
	for (var i = 0; i < InputList.length; i++)
	{ 
		var InputType = InputList[i].type; 

		if(InputType == "image" || InputType == "submit" || InputType == "button")
		{ 
		InputType = InputList[i].getAttribute("id"); 
			var button = document.getElementById(InputList[i].id);
			var ButtonId = InputList[i].id;
			
			EventListener(button,ButtonId);
		}
		
	}
}

function EventListener(button,ButtonId)
{
	if(button.addEventListener)
	{
		button.addEventListener('mouseover',function() { button_rollover(ButtonId); }, true);
		button.addEventListener('mouseout',function() { button_rollover(ButtonId); }, true);
		button.addEventListener('focus',function() { button_rollover(ButtonId); }, true);
		button.addEventListener('blur',function() { button_rollover(ButtonId); }, true);
	}
	else if(button.attachEvent)
	{
		button.attachEvent('onmouseover',function() { button_rollover(ButtonId); });
		button.attachEvent('onmouseout',function() { button_rollover(ButtonId); });
		button.attachEvent('onfocus',function() { button_rollover(ButtonId); });
		button.attachEvent('onblur',function() { button_rollover(ButtonId); });
	}
	else
	{
		button.onclick = button_rollover(ButtonId);
	}
}

function button_rollover(ButtonId)
{
	var Button = document.getElementById(ButtonId);
	var NewClassName = Button.className.split("-");

	if(NewClassName[NewClassName.length - 1] == 'active')
	{
	    NewClassName.pop();
		Button.className = NewClassName.join("-");
	}
	else
	{
		Button.className = NewClassName.join("-"); + '-active';
	}
}






function GiftPopup(GiftId,CheckId)
{
	GiftLayer = document.getElementById(GiftId);
	if (CheckId != '')
		CheckLayer = document.getElementById(CheckId);
	else
		CheckLayer = null;
	
	if(GiftLayer.style.display != 'block')
	{
		GiftLayer.style.display = 'block';
		if (CheckLayer != null)
			CheckLayer.checked = true;
	}
	else
	{
		GiftLayer.style.display = 'none';
		if (CheckLayer != null)
			CheckLayer.checked = false;
	}
	if(typeof sIFR == "function"){
    sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
};
}

function Popup(id)
{
    // JDG 01 June 2010
    // dont show the basket on the product page
    if (document.body.className.toLowerCase() != 'product')
    {
	    Layer = document.getElementById(id);
    	
	    if(Layer.style.display != 'block')
	    {
		    Layer.style.display = 'block';
		    hideSelectBoxes();
		    showSelectBoxes(id);
	    }
	    else
	    {
		    Layer.style.display = 'none';
		    showSelectBoxes();
	    }
	    if(typeof sIFR == "function"){
        sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
        };
    }
}

function HideShow(id)
{
	Layer = document.getElementById(id);
	
	if(Layer.style.display != 'block')
	{
		Layer.style.display = 'block';
	}
	else
	{
		Layer.style.display = 'none';
	}
	if(typeof sIFR == "function"){
    sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
};
}

function showSelectBoxes(id)
{	
	if (id)
	{
		if (document.getElementById(id)) selects = document.getElementById(id).getElementsByTagName("select");
	}
	else
	{
		selects = document.getElementsByTagName("select");
	}

	for (i = 0; i != selects.length; i++)
	{
		selects[i].style.visibility = "visible";
	}
	if(typeof sIFR == "function"){
    sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
};
} 

function hideSelectBoxes()
{
	selects = document.getElementsByTagName("select");

	for (i = 0; i != selects.length; i++) {

		selects[i].style.visibility = "hidden";

	}
}

function AddEvent(obj, evType, fn, useCapture)
{
	if (obj.addEventListener)
	{
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent)
	{
		var r = obj.attachEvent('on' + evType, fn);
		return r;
	}
	else
	{
		obj['on' + evType] = fn;
	}
}

function Hide(id)
{
	Layer = document.getElementById(id);
	
	Layer.style.display = 'none';//This is the funtion that hides the content description on the listing page
}

function Show(id)
{
	Layer = document.getElementById(id);
	
	Layer.style.display = 'block';
	
	if(typeof sIFR == "function"){
    sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
};
	if(typeof sIFR == "function"){
    sIFR.replaceElement("h2", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#909090"}));
};
}

function HideAll(idPrefix)
{	
	var uBound = 99;
	
	for (i=1; i<uBound; i++) {
		var id = idPrefix + i;
		if (document.getElementById(id)) Hide(id);
		else break;
		if(typeof sIFR == "function"){
    sIFR.replaceElement("h1", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#393939"}));
};
		if(typeof sIFR == "function"){
    sIFR.replaceElement("h2", named({sFlashSrc: "/media/sifr/AvantGarde-Book.swf", sColor: "#909090"}));
};
	}
	
}

function ContactPopup()
{
	var Popup = document.getElementById('contact_popup');
	
	if(Popup.style.display != 'block')
	{
		Popup.style.display = 'block';
	}
	else
	{
		Popup.style.display = 'none';		
	}	
}

function BespokeEbury(BespokeId)
{
	var Popup = document.getElementById(BespokeId);
	
	if(Popup.style.display != 'block')
	{
		Popup.style.display = 'block';
	}
	else
	{
		Popup.style.display = 'none';		
	}
}



function VipBoutique(BoutiqueId)
{
	var Popup = document.getElementById(BoutiqueId);
	
	if(Popup.style.display != 'block')
	{
		Popup.style.display = 'block';
	}
	else
	{
		Popup.style.display = 'none';		
	}
}

function EmailPopup()
{
	var Popup = document.getElementById('popup_email');
	
	if(Popup.style.display != 'block')
	{
		Popup.style.display = 'block';
	}
	else
	{
		Popup.style.display = 'none';		
	}
}





function BespokeEbury(BespokeId)
{
	var Popup = document.getElementById(BespokeId);
	
	if(Popup.style.display != 'block')
	{
		Popup.style.display = 'block';
	}
	else
	{
		Popup.style.display = 'none';		
	}
}







function GiftWrappingMovie()
{
	return MoviePopup('/media/movies/Anya_Hindmarch_Gift_Wrapping.mov', 320, 196);
}

function LittleBookMovie()
{
	return MoviePopup('/Resources/must_have/AW08Cut2_Md.mov', 480, 285);
}

function MoviePopup(movieSrc, width, height)
{
	var text = '';
	text += '<html>\r\n';
	text += '<head>\r\n';
	text += '<title>Anya Hindmarch</title>\r\n';
	text += '</head>\r\n';
	text += '<body>\r\n';
	text += '<object CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + width + '" height="' + height + '" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">\r\n';
	text += '<param name="src" value="/media/movies/dummy.mov">\r\n';
	text += '<param name="qtsrc" value="' + movieSrc + '">\r\n';
	text += '<param name="autoplay" value="true">\r\n';
	text += '<param name="loop" value="false">\r\n';
	text += '<param name="controller" value="true">\r\n';
	text += '<param name="type" value="video/quicktime">\n';
	text += '<param name="target" value="myself">\n';
	text += '<embed src="/media/movies/dummy.mov" qtsrc="' + movieSrc + '" width="' + width + '" height="' + height + '" autoplay="true" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"></embed>\r\n';
	text += '</object>\r\n';
	text += '</body>\r\n';
	text += '</html>\r\n';
	
	var newWindow = window.open('Anya Hindmarch', 'VideoPlayer', 'width=' + (width + 20) + ',height=' + (height + 25));
	newWindow.document.write(text);
	newWindow.focus();
	newWindow.document.close();
	
	return false;
}