/* firebug */
if (typeof console == 'undefined') {
	console = new Object;
	console.trace = function() {};
	console.log = function() {};
	console.debug = function() {};
	console.info = function() {};
	console.warn = function() {};
	console.error = function() {};
	console.time = function() {};
	console.timeEnd = function() {};
	console.count = function() {};
}

if(!window_onloads_array) {
	var window_onloads_array = []
}

/* tabs */
Event.observe( window, 'load',function() {
	try {
		lists = $('header').getElementsByTagName('div');
		for(i=0; i<lists.length; i++) {
			if(lists[i].className == 'tab') {
				lists[i].onmouseover = function() {
					this.className = 'tab focused'
				}
				lists[i].onmouseout = function() {
					this.className = 'tab'
				}
			}
		}
	} catch(e) {
		//no header
	}
	try {
		var elements = document.getElementsByTagName('input');
		for(var i=0; i<elements.length; i++) {
			if(elements[i].className.indexOf('ghost_field') != -1) {
				elements[i].onclick = function() {
					this.value='';
					this.style.color='black';
				}
			}
		}
	} catch(e) {
		console.error(e)
	}
	
});

function add_class(obj, class_name) {
	if(obj.className.indexOf(class_name) == -1) {
		if(/MSIE 6/.test(navigator.appVersion)) {
			obj.className += ' ie6_add_class_fix '+obj.className.gsub(' ','_')+'_'+class_name;
      obj.className = obj.className.gsub('__','_');
		} else {
			obj.className += ' '+class_name;
		}
	}
}

function remove_class(obj, class_name) {
	if(obj.className == class_name) {
		obj.className = '';
	} else if(/MSIE 6/.test(navigator.appVersion)) {
		obj.className = obj.className.split(' ie6_add_class_fix ')[0];
	} else {
   	obj.className = obj.className.sub(' '+class_name,'');
	}
}

function open_nav(id) {
  lists = $('sidebar').getElementsByTagName('div');
  for(i=0;i<lists.length;i++) {
    if(lists[i].className.indexOf('fixed') == -1) {
      remove_class(lists[i],'open');
      add_class(lists[i], 'closed');
    }
  }
  obj = $(id);
  if(obj.className.indexOf('fixed') == -1) {
    remove_class(obj, 'closed');
    add_class(obj, 'open');
	}
}


function toggle_nav(id) {
	lists = $('sidebar').getElementsByTagName('div');
	for(i=0;i<lists.length;i++) {
    //isn't the id, is a nav, isn't fixed
		if(lists[i].id != id && lists[i].className.indexOf('nav') != -1 && lists[i].className.indexOf('fixed') == -1) {
			remove_class(lists[i], 'open');
      add_class(lists[i], 'closed');
		}
	}

  obj = $(id);
  if(obj.className.indexOf('fixed') == -1) {
    if(obj.className.indexOf('closed') != -1) {
 	    remove_class(obj, 'closed');
 	   	add_class(obj,'open');
    } else {
      remove_class(obj, 'open');
      add_class(obj,'closed');
    }
  }
}

function set_height() {
	var heights = []
	if(document.documentElement.offsetHeight) {
		heights.push(document.documentElement.offsetHeight)
	}
	if(document.documentElement.scrollHeight) {
		heights.push(document.documentElement.scrollHeight)
	}
	if(document.body.offsetHeight) {
		heights.push(document.body.offsetHeight)
	}
	if(document.body.offsetHeight) {
		heights.push(document.body.offsetHeight)
	}
	heights.sort
	var y=0;
	var hi = '';
	for(i=0;i<heights.length;i++){
		hi += ' '+heights[i]
		if(heights[i] > y) {
			y = heights[i];
		}
	}
	document.body.style.height = (y)+'px';

}

/* make deluxe and add vase price updates */
function product_price(id) {
	price = Number($('standard_price_'+id).value);
	try {
		if($('deluxe_'+id).value > 0) {
			price = Number($('deluxe_price_'+id).value);
		}
	} catch(e) {
	}
	try {
		if($('vase_'+id).name == 'add_vase') {
			price += Number($('vase_price_'+id).value);
		}
	} catch(e) {
	}

	p = (Math.round(price*1000)/1000)

  if($('price_display_'+id).innerHTML.indexOf('£') != -1 || $('price_display_'+id).innerHTML.indexOf('&pound;') != -1) {
    currency = '&pound;'
  } else {
    currency = '&euro; ';
  }

	e = $('price_display_'+id)
	e.innerHTML = currency+p
  if(currency == '&euro; ') {
    e.innerHTML = e.innerHTML.replace('.',',')
  }

	//set strike through price
	if($('strike_price_'+id)) {
		p = (p+Number($('strike_price_'+id).value))
		p = (Math.round(p*1000)/1000)
		e = $('price_display_strike_'+id)
		e.innerHTML = currency+p
		if(currency == '&euro; ') {
			e.innerHTML = e.innerHTML.replace('.',',')
		}
	}

}

function make_deluxe(id) {
	Element.hide($("make_deluxe_"+id));
	Element.show($("make_standard_"+id));
	$('deluxe_'+id).value = 1;
	product_price(id);
}

function make_standard(id) {
	Element.hide($("make_standard_"+id));
	Element.show($("make_deluxe_"+id));
	$("deluxe_"+id).value = 0;
	product_price(id)
}

function add_vase(id) {
	Element.hide($("add_vase_"+id));
	Element.show($("remove_vase_"+id));
	$("vase_"+id).name = 'add_vase';
	product_price(id)
}

function remove_vase(id) {
	Element.hide($("remove_vase_"+id));
	Element.show($("add_vase_"+id));
	$("vase_"+id).name = ''
	product_price(id)
}

function swf_check() {
  try {
    console.debug('swf_check');
    if(($('float') && $('float').style.display == '') || ($('why_choose') && $('why_choose').style.display == '') || ($('social_bookmarks') && $('social_bookmarks').style.display == '')) {
       console.debug('swf_check hide swf');
       $('swf_header').style.width = 0;
    } else {
       console.debug('swf_check show swf');
       $('swf_header').style.width = '';
    }
  } catch(e) {
    console.error("swf_check() error: "+e)
  }
}

/* customer comments box, disabled rotation, added shuffle */
var customer_comments_array = [];
function customer_comments(value) {
	if(value) {
		customer_comments_array = value;
	}
	return customer_comments_array;
}
function customer_comments_update(i) {
	customer_comments_array = customer_comments()
	i += 1;
	if(i>customer_comments_array.length) {
		i=1
	}
	index = i-1;
	index = Math.floor(Math.random()*customer_comments_array.length)
	$('customer_comments_box').innerHTML = customer_comments_array[index].innerHTML;
	//new Effect.Highlight('customer_comments_box',{duration:1,from:.5})
	//setTimeout('customer_comments_update('+i+')',9000);
}

function bookmark(url,title) {
	if(!url) {
		url = window.location.href;
	}
	if(!title) {
		title = document.title
	}
	try {
		window.sidebar.addPanel(title, url,"");
	} catch(e) {
		try {
			window.external.AddFavorite(url,title);
		} catch(e) {
			alert('Your browser does not support this feature, please add the bookmark via the browser menu.')
		}
	}
}


/* tooltip functions */
// position of the tooltip relative to the mouse in pixel //
var offsetx = 6;
var offsety =  4;
var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function newelement(newid,classname) { 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;
				if(classname === undefined){
				} else {
					el.className = classname;
				};
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 

function getmouseposition(e) {
    if(document.getElementById)
    {
        var iebody=(document.compatMode && 
        	document.compatMode != 'BackCompat') ? 
        		document.documentElement : document.body;
        pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
        pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+pagex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+pagey+offsety) + 'px';
    }
}
function tooltip(tip,class_name) {
  if(tip==false) {
    document.getElementById('tooltip').style.display = 'none';
  } else if(tip) {
    if(!document.getElementById('tooltip')) {
      newelement('tooltip', class_name);
    }
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
  }
}
/* end tooltip functions */


/* reminder selector */

function reminder_kind_change(input) {
  Element.hide('reminder_kind_yearly');
  Element.hide('reminder_kind_monthly');
  Element.hide('reminder_kind_weekly');
  Element.show('reminder_kind_'+input.value);

  select = $('reminder_offset');
  options = select.getElementsByTagName('option');
  if(input.value == 'weekly') {
    stop = 8;
  } else {
    stop = 31;
  }

  options = $('reminder_offset').getElementsByTagName('option');
  for(i=0; i<options.length; i++) {
    if(options[i].value >= stop) {
      Element.hide(options[i]);
    } else {
      Element.show(options[i]);
    }
  }
  if(select.value >= stop) {
    select.value = stop-1;
  }
}
