var mousex = 0;
var mousey = 0;
var ajax_status = false;
var mouse_x_offset = null;
var mouse_y_offset = null;
var img_pos = null;
var scrolling = false;
var scroll_timer = false;
var scroll_obj = null;
var selected_size = new Array();
var selected_style = new Array();
var check_timeout = null;
var saved_total;
var _scroll_anchor = false;
var offset = new Array;
offset.x = 0;
offset.y = 0;
var offsetset = false;

function init()
{
	document.onmousemove = mouse_move;

	document.onmouseup = function()
	{
		if (_scroll_anchor)
		{
			_scroll_anchor = false;
			offsetset = false;
		}
	}
}

function $(obj_id)
{
	return document.getElementById(obj_id);
}

function activate_tab(num,total)
{
	for(x=1; x<=total; x++)
	{
		if (x != num)
		{
		    if(x == 1) $('first_edge').className = "first_edge";
			if($("tab_title_"+x))
			{
				$("tab_title_"+x).className = "tab_title";
				$("tab_title_wrap_"+x).className = "tab_title_wrap";
			}
			if(x == num-1 && $("middle_"+x)) $("middle_"+x).className = "middle_act_right";
			else
			{
				if($("middle_"+x)) $("middle_"+x).className = "middle";
			}
			if(x == total) $("last_edge_"+x).className = "edge";
			if($("tab_content_"+x)) $("tab_content_"+x).className = "hidden";
		}
		else
		{
		    if(x == 1) $('first_edge').className = "first_edge_act";
		    $("tab_title_"+x).className = "tab_title_act";
		    $("tab_title_wrap_"+x).className = "tab_title_wrap_act";
			if($("middle_"+x)) $("middle_"+x).className = "middle_act_left";
			if(x == total) $("last_edge_"+x).className = "last_edge_"+x+"_act";
			$("tab_content_"+x).className = "";
		}
	}
}

function preload_images(){
	var d = document;
	if(d.images){
		if(!d.imgs) d.imgs=new Array();
    	var i;
		var j=d.imgs.length;
		var a=preload_images.arguments;
		for(i=0; i<a.length; i++){
			if (a[i].indexOf("#")!=0){
				d.imgs[j]=new Image;
				d.imgs[j++].src=a[i];
			}
		}
	}
}


//Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
//Check if we are using IE.
try
{
	//If the Javascript version is greater than 5.
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
	//If not, then use the older active x object.
	try
	{
		//If we are using Internet Explorer.
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (E)
	{
		//Else we must be using a non-IE browser.
		xmlhttp = false;
	}
}

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
	xmlhttp = new XMLHttpRequest();
}


function make_request(server_page, obj_id)
{
	if (server_page.indexOf('?') > -1) server_page = server_page+"&"+time();
	else server_page = server_page+"?"+time();
	xmlhttp.open("GET", server_page);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			var content = xmlhttp.responseText;
			if (obj_id)
			{
				$(obj_id).innerHTML = content;

				var ajaxScript = $(obj_id).getElementsByTagName("script");
				if(ajaxScript.length)
				{
					for (x = 0;x < ajaxScript.length; x++)
					{
						eval(ajaxScript[x].innerHTML);
					}
				}
			}
			xmlhttp.onreadystatechange = function(){};
			ajax_status = true;
		}
	}
	xmlhttp.send(null);
}

function get_position(e)
{
	var left = 0;
	var top  = 0;


	while (e.offsetParent)
	{
		left += e.offsetLeft - e.offsetParent.scrollLeft;
		top  += e.offsetTop - e.offsetParent.scrollTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x:left, y:top};
}

function mouse_coords(ev)
{
	if(ev.pageX || ev.pageY)
	{
		return {x:ev.pageX, y:ev.pageY};
	}
	return {
		x:(ev.clientX + document.body.scrollLeft - document.body.clientLeft),
		y:(ev.clientY + document.body.scrollTop  - document.body.clientTop)
	};
}

/*function mouse_move(ev)
{
	ev = ev || window.event;

	var mouse_pos = mouse_coords(ev);

	mousex = mouse_pos.x;
	mousey = mouse_pos.y;

	if(img_pos)
	{
		backx = (Math.ceil((mousex-img_pos.x)*2.69))-240;
		backy = (Math.ceil((mousey-img_pos.y)*2.69))-200;
		if(backx < 0) backx = 0;
		if(backy < 0) backy = 0;
		if(backx > 1000) backx = 1000;
		if(backy > 1000) backy = 1000;
		//console.log("backx: "+backx+", backy: "+backy);
		//backPos = "-"+backx+"px "+"-"+backy+"px";
		//if(mousex-61>img_pos.x && mousex+61<img_pos.x+offsetImgWidth)

		zoom_left = mousex-80;
		if (zoom_left < img_pos.x) zoom_left = img_pos.x;
		if (zoom_left + 121 > img_pos.x + offsetImgWidth) zoom_left = img_pos.x + offsetImgWidth - 121;

		$("zoom_square").style.left = zoom_left+"px";
		$("zoom1_img").style.left = (0-backx)+"px";

		//if(mousey-56>img_pos.y && mousey+56<img_pos.y+offsetImgHeight)

		zoom_top = mousey-56;
		if (zoom_top < img_pos.y) zoom_top = img_pos.y;
		if (zoom_top + 112 > img_pos.y + offsetImgHeight) zoom_top = img_pos.y + offsetImgHeight - 112;

		$("zoom_square").style.top = zoom_top+"px";
		$("zoom1_img").style.top = (0-backy)+"px";

		if(mousex<img_pos.x || mousex>img_pos.x+offsetImgWidth){
			nozoom();
		}
		if(mousey<img_pos.y || mousey>img_pos.y+offsetImgHeight){
			nozoom();
		}
	}

	if (_scroll_anchor)
	{
		if (!offsetset)
		{
			anchor_pos = get_position(_scroll_anchor);
			_scroll_bar = $('scroll_bar');
			_scroll_content = $('scroll_content');
			_scroll_holder = $('scroll_holder');
			scroll_bar_pos = get_position(_scroll_bar);
			offset.x = mouse_pos.x - anchor_pos.x;
			offset.y = mouse_pos.y - anchor_pos.y;
			offsetset = true;
		}
		else
		{
			var scroll_top = mouse_pos.y - scroll_bar_pos.y - offset.y;
			if (scroll_top < 0) scroll_top = 0;
			if (scroll_top + _scroll_anchor.offsetHeight > _scroll_bar.offsetHeight) scroll_top = _scroll_bar.offsetHeight - _scroll_anchor.offsetHeight;

			_scroll_anchor.style.top = scroll_top + "px";

			var percent = (100 / (_scroll_bar.offsetHeight - _scroll_anchor.offsetHeight)) * scroll_top;

			_scroll_content.scrollTop = ((percent / 100) * (_scroll_content.scrollHeight - _scroll_holder.offsetHeight));
		}
	}
	return false;
}*/


function mouse_moveCT(x,y){
    
    //console.log("statr new function");
	mousex = x;
	mousey = y;

	if(img_pos)
	{
		backx = (Math.ceil((mousex-img_pos.x)*2.69))-240;
		backy = (Math.ceil((mousey-img_pos.y)*2.69))-205;
		if(backx < 0) backx = 0;
		if(backy < 0) backy = 0;
		if(backx > 1000) backx = 1000;
		if(backy > 1000) backy = 1000;
		//console.log("backx: "+backx+", backy: "+backy);
		//backPos = "-"+backx+"px "+"-"+backy+"px";
		//if(mousex-61>img_pos.x && mousex+61<img_pos.x+offsetImgWidth)

		zoom_left = mousex-80;
		if (zoom_left < img_pos.x) zoom_left = img_pos.x;
		if (zoom_left + 121 > img_pos.x + offsetImgWidth) zoom_left = img_pos.x + offsetImgWidth - 121;

		$("zoom_square").style.left = zoom_left+"px";
		$("zoom1_img").style.left = (0-backx)+"px";

		//if(mousey-56>img_pos.y && mousey+56<img_pos.y+offsetImgHeight)

		zoom_top = mousey-56;
		if (zoom_top < img_pos.y) zoom_top = img_pos.y;
		if (zoom_top + 112 > img_pos.y + offsetImgHeight) zoom_top = img_pos.y + offsetImgHeight - 112;

		$("zoom_square").style.top = zoom_top+"px";
		$("zoom1_img").style.top = (0-backy)+"px";

		if(mousex<img_pos.x || mousex>img_pos.x+offsetImgWidth){
			nozoom();
		}
		if(mousey<img_pos.y || mousey>img_pos.y+offsetImgHeight){
			nozoom();
		}
	}

	if (_scroll_anchor)
	{
		if (!offsetset)
		{
			anchor_pos = get_position(_scroll_anchor);
			_scroll_bar = $('scroll_bar');
			_scroll_content = $('scroll_content');
			_scroll_holder = $('scroll_holder');
			scroll_bar_pos = get_position(_scroll_bar);
			offset.x = mouse_pos.x - anchor_pos.x;
			offset.y = mouse_pos.y - anchor_pos.y;
			offsetset = true;
		}
		else
		{
			var scroll_top = mouse_pos.y - scroll_bar_pos.y - offset.y;
			if (scroll_top < 0) scroll_top = 0;
			if (scroll_top + _scroll_anchor.offsetHeight > _scroll_bar.offsetHeight) scroll_top = _scroll_bar.offsetHeight - _scroll_anchor.offsetHeight;

			_scroll_anchor.style.top = scroll_top + "px";

			var percent = (100 / (_scroll_bar.offsetHeight - _scroll_anchor.offsetHeight)) * scroll_top;

			_scroll_content.scrollTop = ((percent / 100) * (_scroll_content.scrollHeight - _scroll_holder.offsetHeight));
		}
	}
	return false;
     
}


function mouse_move(ev)
{
	ev = ev || window.event;

	var mouse_pos = mouse_coords(ev);

	mousex = mouse_pos.x;
	mousey = mouse_pos.y;
    if (typeof ClickTaleExec == "function") {
            ClickTaleExec("mouse_moveCT("+mousex+","+mousey+")");
    }
	if(img_pos)
	{
		backx = (Math.ceil((mousex-img_pos.x)*2.69))-240;
		backy = (Math.ceil((mousey-img_pos.y)*2.69))-205;
		if(backx < 0) backx = 0;
		if(backy < 0) backy = 0;
		if(backx > 1000) backx = 1000;
		if(backy > 1000) backy = 1000;
		//console.log("backx: "+backx+", backy: "+backy);
		//backPos = "-"+backx+"px "+"-"+backy+"px";
		//if(mousex-61>img_pos.x && mousex+61<img_pos.x+offsetImgWidth)

		zoom_left = mousex-80;
		if (zoom_left < img_pos.x) zoom_left = img_pos.x;
		if (zoom_left + 121 > img_pos.x + offsetImgWidth) zoom_left = img_pos.x + offsetImgWidth - 121;

		$("zoom_square").style.left = zoom_left+"px";
		$("zoom1_img").style.left = (0-backx)+"px";

		//if(mousey-56>img_pos.y && mousey+56<img_pos.y+offsetImgHeight)

		zoom_top = mousey-56;
		if (zoom_top < img_pos.y) zoom_top = img_pos.y;
		if (zoom_top + 112 > img_pos.y + offsetImgHeight) zoom_top = img_pos.y + offsetImgHeight - 112;

		$("zoom_square").style.top = zoom_top+"px";
		$("zoom1_img").style.top = (0-backy)+"px";

		if(mousex<img_pos.x || mousex>img_pos.x+offsetImgWidth){
			nozoom();
		}
		if(mousey<img_pos.y || mousey>img_pos.y+offsetImgHeight){
			nozoom();
		}
	}

	if (_scroll_anchor)
	{
		if (!offsetset)
		{
			anchor_pos = get_position(_scroll_anchor);
			_scroll_bar = $('scroll_bar');
			_scroll_content = $('scroll_content');
			_scroll_holder = $('scroll_holder');
			scroll_bar_pos = get_position(_scroll_bar);
			offset.x = mouse_pos.x - anchor_pos.x;
			offset.y = mouse_pos.y - anchor_pos.y;
			offsetset = true;
		}
		else
		{
			var scroll_top = mouse_pos.y - scroll_bar_pos.y - offset.y;
			if (scroll_top < 0) scroll_top = 0;
			if (scroll_top + _scroll_anchor.offsetHeight > _scroll_bar.offsetHeight) scroll_top = _scroll_bar.offsetHeight - _scroll_anchor.offsetHeight;

			_scroll_anchor.style.top = scroll_top + "px";

			var percent = (100 / (_scroll_bar.offsetHeight - _scroll_anchor.offsetHeight)) * scroll_top;

			_scroll_content.scrollTop = ((percent / 100) * (_scroll_content.scrollHeight - _scroll_holder.offsetHeight));
		}
	}
	return false;
}

function handle(delta)
{
	if (!delta) return false;
	if (typeof(_scroll_content) == "undefined") _scroll_content = $('scroll_content');
	if (typeof(_scroll_bar) == "undefined") _scroll_bar = $('scroll_bar');
	if (typeof(__scroll_anchor) == "undefined") __scroll_anchor = $('scroll_anchor');

	if (delta < 0)
	{
		_scroll_content.scrollTop = _scroll_content.scrollTop + 10;
	}
	else
	{
		_scroll_content.scrollTop = _scroll_content.scrollTop - 10;
	}

	var percent = (100 / (_scroll_content.scrollHeight - _scroll_content.offsetHeight)) * _scroll_content.scrollTop;

	__scroll_anchor.style.top = ((percent / 100) * (_scroll_bar.offsetHeight - __scroll_anchor.offsetHeight)) + "px";

}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code.
 * If you use your own event management code, change it as required.
 */
function initscroll(obj)
{
	__scroll_anchor = $('scroll_anchor');
	_scroll_bar = $('scroll_bar');
	_scroll_content = $('scroll_content');

	var percent = (100 / _scroll_content.scrollHeight) * _scroll_content.offsetHeight;
	var scroll_bar_height = (percent / 100) * _scroll_bar.offsetHeight;
	__scroll_anchor.style.height = scroll_bar_height + "px";

	if (obj.addEventListener)
	        /** DOMMouseScroll is for mozilla. */
	        obj.addEventListener('DOMMouseScroll', wheel, false);
	/** IE/Opera. */
	obj.onmousewheel = wheel;
}

function click_scroll()
{
	_scroll_bar = $('scroll_bar');
	_scroll_content = $('scroll_content');
	__scroll_anchor = $('scroll_anchor');
	scroll_anchor_pos = get_position(__scroll_anchor);
	scroll_bar_pos = get_position(_scroll_bar);
	if (mousey > scroll_bar_pos.y && mousey < scroll_anchor_pos.y)
	{
		_scroll_content.scrollTop = _scroll_content.scrollTop - _scroll_content.offsetHeight;
	}
	else if (mousey > scroll_anchor_pos.y + __scroll_anchor.offsetHeight && mousey < scroll_bar_pos.y + _scroll_bar.offsetHeight)
	{
		_scroll_content.scrollTop = _scroll_content.scrollTop + _scroll_content.offsetHeight;
	}

	var percent = (100 / (_scroll_content.scrollHeight - _scroll_content.offsetHeight)) * _scroll_content.scrollTop;

	__scroll_anchor.style.top = ((percent / 100) * (_scroll_bar.offsetHeight - __scroll_anchor.offsetHeight)) + "px";
}

function time()
{
	var d = new Date();
	return d.getTime();
}

function debug(debug_id,debug_var)
{
	if (!(debug_element = document.getElementById('debug_'+debug_id)))
	{
		var debug_element = document.createElement("div");
		debug_element.style.position = "fixed";
		debug_element.style.right="10px";
		debug_element.style.height="15px";
		debug_element.style.backgroundColor="#E0E0E0";
		debug_element.style.font="13px/17px verdana";
		debug_element.id = "debug_"+debug_id;
		debug_element.style.bottom = 10+(debug_id*20)+"px";
		document.body.appendChild(debug_element);
	}
	debug_element.innerHTML = debug_var;
}

function zoom()
{
    if (typeof ClickTaleExec == "function") {
            ClickTaleExec("zoom()");
    }
	img_pos = get_position($("product_img_main"));
	offsetImgHeight = $("product_img_main").height;
	offsetImgWidth = $("product_img_main").width;
	$("tab_text").className = "hidden";
	$("zoom1").className = "zoom";
	$("zoom_square").className = "";
}

function nozoom()
{
	img_pos = 0;
	$("zoom1").className = "zoom hidden";
	$("tab_text").className = "";
	$("zoom_square").className = "hidden";
}

function prod_popup(url){
	img = $("product_img_main").src;
	arr = img.split("/");
	x = arr.length-1;
	img = arr[x];
	arr = img.split(".");
	img = arr[0];
	window.open(url+"?img="+img, 'product_image', 'menubar=false, status=false, scrollbars=1, resizable=1, location=false, top=10, left=10, width=800, height=600');
}

function popup(url,w,h){
	window.open(url, 'popup', 'menubar=false, status=false, scrollbars=1, resizable=1, location=false, top=10, left=10, width='+w+', height='+h);
}

function pop_stock(type, id, quantity_id)
{
	old_quantity = 0;
	if (!quantity_id) quantity_id = 0;
	if (type == "size")
	{
		if (selected_size[quantity_id] == id) return false;
		selected_size[quantity_id] = id;
	}
	else if (type == "style")
	{
		//if (selected_style[quantity_id] == id) return false;
		selected_style[quantity_id] = id;
	}

	s_size = selected_size[quantity_id] || 0;
	s_style = selected_style[quantity_id] || 0;

	if (quantity_id) quantity_select = $('quantity_'+quantity_id);
	else quantity_select = $('quantity');

	old_quantity = quantity_select.selectedIndex;

	quantity_select.options.length = 0;

	if (quantity_id)
	{
		store = eval("store_"+quantity_id);
		quantity_select.options[0] = new Option(0,0);
		qoffset = 0;
	}
	else qoffset = 1;

	if (store[s_size+"_"+s_style])
	{
		if (store[s_size+"_"+s_style] > 4) qlist = 5;
		else qlist = store[s_size+"_"+s_style];

		for(i = 1;i <= qlist; i++)
		{
			quantity_select.options[i-qoffset] = new Option(i,i);
		}
		if (old_quantity && old_quantity >= 1 && old_quantity <= qlist) quantity_select.selectedIndex = old_quantity;
		else quantity_select.selectedIndex = !qoffset;
	}
	else if (store[s_size+"_"+s_style] === 0) quantity_select.options[0] = new Option('Sold out',0);
	else quantity_select.options[0] = new Option('',0);
}

function c_select(colour,style_id,x)
{
	if(document.selector)				//on the product page
	{
		document.selector.style_id.value = style_id;
		x = 0;
		while(colEl=$("colour"+x))
		{
			if(x!=colour) colEl.style.border = "1px #CCCCCC solid";
			if(colEl.style.backgroundColor=="rgb(255, 255, 255)") colEl.style.border = "1px brown solid";
			x++;
		}
		$("colour"+colour).style.border = "1px #000 solid";
		pop_stock("style", style_id);
	}
	else if($('colourInput'+x))			//on the basket page
	{
		$('colourInput'+x).value = style_id;
		opacity('picker'+x, 100, 0, 500);
		$('square'+x).style.background = $('colour_'+x+'_'+c).style.background;
	}
}

function swap_image(id, img_obj, bgimg)
{
	if(img_obj)
	{
		img = img_obj.src;
		alt = img_obj.alt;
		img = img.replace(/thumbs/,"main");
		$(id).src = img;
		$(id).alt = alt;
		if(bgimg)
		{
			img = img.replace(/main/,"large");
			$("zoom1_img").src = img;
		}
		for(var i = 0; i < 5; i++)
		{
			if($("overlay"+i) && $("overlay"+i).id == "overlay"+img_obj.id)
			{
				$("overlay"+i).className = 'active';
			}
			else
			{
				if($("overlay"+i))
				{
					$("overlay"+i).className = '';
				}
			}
		}
	}
}
function goBack()
{
		history.back();
}
function saveAndNext()
{
		$('next').value = "1";
		$('edit_account').submit();
}
function saveAndContinue()
{
		$('next').value = "";
		$('edit_account').submit();
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
		dir = "down";
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "','" + dir + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
		dir = "up";
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "','" + dir + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id, dir) {
    var object = $(id).style;
	if(opacity == 0 && dir == "up")
	{
		if($(id).tagName == "TR") object.display = "";
		else object.display = "block";
	}
    object.opacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	if(opacity == 0 && dir == "down") object.display = "none";
}

function hide(obj)
{
		opacity(obj, 100, 0, 500);
}

function getScrollY() {
	var scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}

function send(code)
{
		$('product_code').value = code;
		if($('wishlist'))
		{
				var clientWidth = $('wishlist').offsetWidth;
				var clientHeight = $('wishlist').offsetHeight;
		}
		if($('product'))
		{
				var clientWidth = $('product').offsetWidth;
				var clientHeight = $('product').offsetHeight;
		}
		if($('basket'))
		{
				var clientWidth = $('basket').offsetWidth;
				var clientHeight = $('basket').offsetHeight;
		}
		var sendBoxWidth = $('send_to_friend').offsetWidth;
		var sendBoxHeight = $('send_to_friend').offsetHeight;
		var style = $('send_to_friend').style;
		var scrollTop = getScrollY();
		style.top = (((clientHeight/2)-(sendBoxHeight/2))/2)+scrollTop-90+ "px";
		style.left = ((clientWidth/2)-(sendBoxWidth/2))/2 + "px";
		opacity('send_to_friend', 0, 100, 250);
}

function showFriend()
{
		if($('wishlist'))
		{
				var clientWidth = $('wishlist').clientWidth;
				var clientHeight = $('wishlist').clientHeight;
		}
		if($('product'))
		{
				var clientWidth = $('product').clientWidth;
				var clientHeight = $('product').clientHeight;
		}
		if($('basket'))
		{
				var clientWidth = $('basket').clientWidth;
				var clientHeight = $('basket').clientHeight;
		}
		var sendBoxWidth = $('send_to_friend').clientWidth;
		var sendBoxHeight = $('send_to_friend').clientHeight;
		var style = $('send_to_friend').style;
		style.top = (((clientHeight/2)-(sendBoxHeight/2))/2)-90 + "px";
		style.left = ((clientWidth/2)-(sendBoxWidth/2))/2 + "px";
		style.opacity = 1;
		style.filter = "alpha(opacity=1)";
		style.display = "block";
}
function showPicker(n)
{
		if($('picker'+n))
		{
				opacity('picker'+n, 0, 100, 250);
		}
		else return false;
}

function populate(checkbox,js_array)
{
		for(x in js_array){
				y = x.replace(/billing/, "delivery")
				if($(y))
				{
						if(checkbox.checked == true)
						{
								z = js_array[x];
								$(y).value =  z;
								//console.log("x: " + x + ", y: " + y + ", z: " + z);
						}
						else
						{
								$(y).value =  '';
						}
				}
		}
}

function populate_select(number, form_to)
{
	if (!number) return;
	var box2 = $(form_to);
	box2.options.length = 0;
	if (store[number])
	{
		var list = store[number];
		for(i=0;i<list.length;i+=2)
		{
			box2.options[i/2] = new Option(unescape(list[i]),list[i+1]);
		}
	}
	else
	{
		box2.options[0] = new Option("Select", "0");
	}
}

function giftWrap(obj,price,vat)
{
		if(obj.checked == true && $('gift') && $('total'))
		{
				$('gift').innerHTML = price.toFixed(2);
				/*v = $('vat').innerHTML;
				wrap_vat = Math.floor((price * vat)*100)/100;
				v = (v*1) + wrap_vat;
				$('vat').innerHTML = v;*/
				t = $('total').innerHTML;
				t = (t*1)+price;
				$('total').innerHTML = t.toFixed(2);
				saved_total = t;
		}
		else if(obj.checked == false && $('gift') && $('total'))
		{
				$('gift').innerHTML = '0.00';
				t = $('total').innerHTML;
				t = t*1-price;
				$('total').innerHTML = t.toFixed(2);
				saved_total = t;
		}
		else return false;
}

function checkLength(obj)
{
		var currentLength = obj.value.length;
		var maxLength = obj.getAttribute('maxlength');
		var value = obj.value;
		if (currentLength > maxLength) obj.value = value.substr(0,value.length-1);
		if($('charCount')) $('charCount').innerHTML = obj.value.length;
}

function addToWishlist(){
		if($('do') && $('product_form')){
				$('do').value = "wishlist";
				$('product_form').submit();
		}
		else return false;
}

function fadeAdded()
{
    if(!$('added')) return false;
	else setTimeout("hide('added')",3000);
}

function scroll(a)
{

	if (!a) return false;
	if (scrolling) return false;
	amount = a;
	from = scroll_obj.scrollLeft;
	//console.log(from);
	if (from == 0 && a < 0) return false;
	if (from + a >= scroll_obj.scrollWidth) return false;
	//scroller_unfocus();
	scrolling = true;
	scroll_it();
}
function scroll_it()
{
	var offset = 0;
	if (amount < 0) offset = -12;
	else offset = 12;

	if (amount > 0)
	{
		if (scroll_obj.scrollLeft+offset < from+amount && (scroll_obj.scrollLeft + offset + scroll_obj.clientWidth) < scroll_obj.scrollWidth)
		{
			scroll_obj.scrollLeft+=offset;
			setTimeout(scroll_it,20);
		}
		else
		{
			scroll_obj.scrollLeft = from+amount;
			scrolling = false;
		}
	}
	else
	{
		if ((scroll_obj.scrollLeft + offset) < 0)
		{
			scroll_obj.scrollLeft = 0;
			scrolling = false;
		}
		else if (scroll_obj.scrollLeft+offset > from+amount)
		{
			scroll_obj.scrollLeft+=offset;
			setTimeout(scroll_it,20);
		}
		else
		{
			scroll_obj.scrollLeft = from+amount;
			scrolling = false;
		}
	}
}

function check_code(input_field,path)
{
	if(check_timeout) clearTimeout(check_timeout);
	check_timeout = setTimeout(function ()
		{
			if(input_field.value)
			{
				$('promo_check').innerHTML = '<img src="'+path+'images/core/ajaxloader.gif" alt=""/>';
				make_request(path+'ajax/check_code.php?c='+input_field.value,'promo_check');
			}
			else $('promo_check').innerHTML = '';
		},500);
}