function check_image_ajax(stranka) {
 var httpRequest;
     
 if(typeof window.ActiveXObject != 'undefined') {
  httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
 } else {  
  httpRequest = new XMLHttpRequest();
 }
 httpRequest.open("GET", stranka, true);
 httpRequest.onreadystatechange = function() {
  if (httpRequest.readyState == 4) {      
   if(httpRequest.status == 200) {
      document.getElementById("check_image").innerHTML=httpRequest.responseText;            
   } else {
    document.getElementById("check_image").innerHTML="Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText;
   }
  } else {
   document.getElementById("check_image").innerHTML="Loading ...";
  } 
 }
 httpRequest.send(null);
}

function refresh_basket(stranka) {
 var httpRequest;
     
 if(typeof window.ActiveXObject != 'undefined') {
  httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
 } else {  
  httpRequest = new XMLHttpRequest();
 }
 httpRequest.open("GET", stranka, true);
 httpRequest.onreadystatechange = function() {
  if (httpRequest.readyState == 4) {      
   if(httpRequest.status == 200) {
      document.getElementById("basket_write").innerHTML=httpRequest.responseText;            
   } else {
    document.getElementById("basket_write").innerHTML="Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText;
   }
  } else {
   document.getElementById("basket_write").innerHTML="Loading ...";
  } 
 }
 httpRequest.send(null);
}


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[15,25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 150;	// maximum image size.
var defaultimagewidth = 140;	// maximum image size.

var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("floating_preview").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("floating_preview")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-5000px"
	clearTimeout(timer);
}

function showtrail(product,width){
	i = product;
	w = width;
	timer = setTimeout("show('"+i+"',w);",200);
}
function show(product,width){
    var stranka;
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>150 && docheight>100)) {
		( width == 0 ) ? width = defaultimagewidth: '';
//		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
//		height+=55
//		defaultimageheight = height
		defaultimagewidth = width
	
		document.onmousemove=followmouse; 

		newHTML = '';
                /* stranka ktera se ma zobzazit */
                newHTML = newHTML + '<div class="floating_preview" style=" width: '+width+'px; height: auto;">';	
//                newHTML = newHTML + title + '<br /><br />';
		

		/* nahled s detailem produktu pomoci AJAX */		
		newHTML = newHTML + '<div id="ajax">';	
    		newHTML = newHTML + '</div>';
		newHTML = newHTML + '</div>';
				
		gettrailobjnostyle().innerHTML = newHTML;		
		gettrailobj().display="block";
		ajax(product);
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight);
	
	if (typeof e != "undefined"){
		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
		    if (e.pageX < defaultimagewidth + 2*offsetfrommouse[0]) {
    		         xcoord = e.pageX - xcoord - defaultimagewidth / 2;// posunuti na stred mysi
		    } else {
			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
		    }	
		} else {
			xcoord += e.pageX;
		}
		if ((docheight + truebody().scrollTop - e.pageY) < (zmer(document.getElementById("ajax")) + 2*offsetfrommouse[1])){            // 		
			// mala mezera zespodu
			ycoord = e.pageY - zmer(document.getElementById("ajax")) - 2 * offsetfrommouse[1];
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
	        // alert(docheight + truebody().scrollTop - event.clientY);
		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
		    if (event.clientX < defaultimagewidth + 2*offsetfrommouse[0]) {
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth / 2; // posunuti na stred mysi
		    } else {
			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
		    }	
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight + truebody().scrollTop - event.clientY < (zmer(document.getElementById("ajax")) + 2 * offsetfrommouse[1])) {       //                		       
		        ycoord = event.clientY - zmer(document.getElementById("ajax")) - 2 * offsetfrommouse[1] + truebody().scrollTop;
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

//	if (typeof e != "undefined"){
//		if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
//			xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
//		} else {
//			xcoord += e.pageX;
//		}
//		if (docheight - e.pageY < defaultimageheight + 2*offsetfrommouse[1]){
//			ycoord += e.pageY - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - truebody().scrollTop));
//		} else {
//			ycoord += e.pageY;
//		}
//
//	} else if (typeof window.event != "undefined"){
//		if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
//			xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
//		} else {
//			xcoord += truebody().scrollLeft+event.clientX
//		}
//		if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
//			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
//		} else {
//			ycoord += truebody().scrollTop + event.clientY;
//		}
//	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"

} 
function ajax(stranka) {
 var httpRequest;
    
 if(typeof window.ActiveXObject != 'undefined') {
  httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
 } else {  
  httpRequest = new XMLHttpRequest();
 }
 httpRequest.open("GET", stranka, true);
 httpRequest.onreadystatechange = function() {
  if (httpRequest.readyState == 4) {      
   if(httpRequest.status == 200) {
      document.getElementById("ajax").innerHTML=httpRequest.responseText;
      //alert(zmer(document.getElementById("ajax")));
      //var text;
      //text = httpRequest.responseText;
      // alert(window.screen.availHeight);
      //while (zmer(document.getElementById("ajax")) > window.screen.availHeight) {
      // text = text.substring(0,text.length-2); // zkraceni o 1 znak
      // document.getElementById("ajax").innerHTML=text;
      //}
      gettrailobj().height=zmer(document.getElementById("ajax"))+"px";
   } else {
//    alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
    document.getElementById("ajax").innerHTML="Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText;
   }
  } else {
   document.getElementById("ajax").innerHTML="Loading ...";
  } 
 }
 httpRequest.send(null);
}

function style2px(hodnota) {
 if (hodnota) return Number(hodnota.substr(0,hodnota.indexOf("px")));
 else return 0;
}

function zmer($prvek) {
 var ee;
 try {
  var $cs=document.defaultView.getCompusedStyle($prvek,'');
  $val=style2px($cs.getPropertyValue("height"));
 }
 catch(ee) {
  $val=($prvek.offsetHeight);
  if ($val < 0) $val=0;
 }
 return $val;
}

mmopeni = new Image();	mmopeni.src = "./img/menu/opentree.gif";
mmclosei = new Image();	mmclosei.src = "./img/menu/closetree.gif";

function mms(id,maincategory,hide) {
 var podmenu;
 if (maincategory === false) {
  // podkategorie
  if (podmenu= document.getElementById("sub_sub_"+id)) {
   var visible = (podmenu.style.display != 'none');
   if (visible) {
    if (hide) {
     podmenu.style.display='none';
     eval("document.getElementById('main_obr"+id+"').src=mmclosei.src");
    } 
   } else {
    podmenu.style.display='block';
    eval("document.getElementById('main_obr"+id+"').src=mmopeni.src");   
   }
  }
 } else {
  // hlavni kategorie
  if (podmenu= document.getElementById("main_main_"+id)) {
   var visible = (podmenu.style.display != 'none');
   if (visible) {
    if (hide) {
     podmenu.style.display='none';
     eval("document.getElementById('main_main_obr"+id+"').src=mmclosei.src");
    } 
   } else {
    podmenu.style.display='block';
    eval("document.getElementById('main_main_obr"+id+"').src=mmopeni.src");   
   }
  }  
 }
}

