function IE_browser(){
	var IE =v=false,n;try{n=navigator.appVersion;IE=(n.indexOf('MSIE')!=-1)}catch(e){}
	if(IE)v=n.substr(n.indexOf('MSIE')+5,1);return parseInt(v);
}
function set_cookie(id, value) {
	var today = new Date();
	var expires = new Date();
expires.setTime(today.getTime() + 1000*60*60*24*365);
document.cookie = escape(id) + "=" + value + ";path=/; expires=" + expires;
}
function get_cookie(id) { 
  if (document.cookie!="") { 
  var toCookie=document.cookie.split("; ")
    for (i=0; i<toCookie.length; i++) { 
      var cookie_name = toCookie[i].split("=")[0];
      var cookie_value = toCookie[i].split("=")[1]; 
      if (cookie_name == id) return unescape(cookie_value)
    }
  }
} 
function container_height(tallest) {
var div = document.getElementsByTagName('div');
	for(var i=0;i<div.length;i++) {
		if(div[i].getAttribute('rel') == 'height_container') {
		div[i].style.height = tallest + "px";
		}
	}
}
function text_shadow(id) {
	/* ThUnDeR  28.09.2010     cien pod napisem
  var div = document.createElement('div');
	div.appendChild(document.createTextNode(id.firstChild.nodeValue));
	id.appendChild(div);
	*/
}
function rel_navigation() {
var tallest = 0;
var div = document.getElementsByTagName('div');
	for(var i=0;i<div.length;i++) {
		if(div[i].getAttribute('rel') == 'shadow') {
			text_shadow(div[i]);
		}
		if(div[i].getAttribute('rel') == 'height_container') {
			if(div[i].offsetHeight > tallest) {
			tallest = div[i].offsetHeight;
			}
		}
		if(div[i].getAttribute('rel') == 'vertical-align-shadow') {
				var padding = (24-((div[i].offsetHeight/16)*10));
				div[i].style.paddingTop = padding + "px";
				text_shadow(div[i]);
				var child=div[i].getElementsByTagName("div");
				child[0].style.top = (padding+2) + "px";
		}
	}
container_height(tallest);
}
function create_compare_button() {
var id = "products_list";
var counter = 0;
	for (i=0; i<document.forms[id].length; i++) {
		if(document.forms[id][i].checked == true) {
		counter++;
		}
	}
	if(counter > 1 & counter <= 4) {
		document.getElementById('compare_button').style.display = "block";
	}
	if(counter > 4 || counter < 2) {
		document.getElementById('compare_button').style.display = "none";
	}
}
function iframe_resize(){
	document.getElementById('load_forum').style.display = "none";
	var height = document.getElementById("iframe_forum").contentWindow.document.body.scrollHeight;
	var width = document.getElementById("iframe_forum").contentWindow.document.body.scrollWidth;
	document.getElementById("iframe_forum").height = height + "px";
	document.getElementById("iframe_forum").width = width + "px";
}
function ajax_request(event) {
	var element = event.findElement('a');
	Event.stop(event);
	new Ajax.Updater('content_products_offer', element.href, {asynchronous:true, onComplete: onCompleteAjax});
	return false;
}
function ajax_onclick(event) {
   //document.getElementById("middle_bar").innerHTML = "";
	new Ajax.Updater('content_products_offer', event, {asynchronous:true});
	return false;
}
function rewriteLinks() {
	links = $$('a');
	for(var i=0;i<links.length;i++) {
		if(links[i].getAttribute('rel') == 'ajax') {
		links[i].observe('click', ajax_request);
		}
	}
		
}
function scrollPosition() {
	document.getElementById('ContainerScrollProducts').scrollTop = get_cookie("ContainerScrollProducts");
}
function onCompleteAjax() {
	scrollPosition();
}
document.observe("dom:loaded",rewriteLinks);
defaultStep=10;
step=defaultStep;

function scrollDivDown(id){
clearTimeout(timerDown);
document.getElementById(id).scrollTop+=step;
set_cookie("ContainerScrollProducts", document.getElementById(id).scrollTop);
timerDown=setTimeout("scrollDivDown('"+id+"')",10);
} 

function scrollDivUp(id){
clearTimeout(timerUp);
document.getElementById(id).scrollTop-=step;
set_cookie("ContainerScrollProducts", document.getElementById(id).scrollTop);
timerUp=setTimeout("scrollDivUp('"+id+"')",10);
} 
timerDown="";
timerUp="";
function stopMe(){
clearTimeout(timerDown);
clearTimeout(timerUp);
}
document.onmousemove=function(){stopMe()}  
function hideProductsGroupBox(id) {
if(!(id=="products_group_box_scroll" || id=="scroll_up" || id=="scroll_down" || id=="offer_link" || id=="compare_button")) {
	if(document.getElementById('products_group_box')) document.getElementById('products_group_box').style.display = "none";
	if(document.getElementById('producer_box')) document.getElementById('producer_box').style.display = "none";
	desactive_menu('group');
	desactive_menu('producer');
	}
}
function active_menu(id) {
document.getElementById('main_'+id+'_button').style.backgroundImage = "url('../new/images/left_blue_bar.jpg')";
}
function desactive_menu(id) {
document.getElementById('main_'+id+'_button').style.backgroundImage = "url('../new/images/left_blue_bar_des.jpg')";
}
function getElementId(e){ 
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) 
targ = targ.parentNode;
hideProductsGroupBox(targ.id);
}

function load_img(img) {
	document.getElementById('product_gallery').style.backgroundImage = "url('../new/thumbnail.php?src=" + img + "&bevel=rounded_rect&round_radius=0&x=300&y=300&scal')";
}
if(IE_browser()){
	window.attachEvent('onload', rel_navigation);
	/* bug IE > 6.0
	window.attachEvent('onload', container_height);*/
}
else
{
	window.addEventListener('load', container_height, false);
	window.addEventListener('load', rel_navigation, false);
}
