var feefoSliding = 0;
var FeefoSlideSpeed = 25;
var feefoParams="";
var feefoMethod = "";
var feefoproto=parent.location.protocol;
var FeefoSliderTop = 0;
if (feefoproto=="file:") {
	feefoproto="http:";
}

var feefoWidth = 0, feefoHeight = 0;

  feefoGetWindowSize();
  window.onresize = function(){feefoGetWindowSize()};
  document.onclick = function (e) {
		e = e || event
                //if the user clicks anywhere except on the logo or the reviews then remove the reviews
		var feefopage = document.getElementById("feefopage");
		if (feefopage.style.right == "3000px") return;		
                  
		var feefotarget = e.target || e.srcElement
		var feefologoa = document.getElementById("feefologoa");

		do {
			if (feefopage == feefotarget || feefologoa == feefotarget) {
				return
			}
			feefotarget = feefotarget.parentNode
		} while (feefotarget)
                if (feefoMethod == "bottomrightsmooth") FeefoSmooth("right");
	        else {
			if (feefoMethod == "bottomleftsmooth") FeefoSmooth("left");
			else {
				feefopage.style.right='3000px';
                		document.getElementById("feefofade").style.display = "none";
                    try { $('youtubevideo').show(); } catch(err) { };
			}
		}
  } 
  
  
  		

function feefoGetWindowSize(){
    feefoSliding = false;
    if (typeof (window.innerWidth) == 'number') {
       //Non-IE
       feefoWidth = window.innerWidth;
       feefoHeight = window.innerHeight;
   } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
       //IE 6+ in 'standards compliant mode'
       feefoWidth = document.documentElement.clientWidth;
       feefoHeight = document.documentElement.clientHeight;
   } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
       //IE 4 compatible
       feefoWidth = document.body.clientWidth;
       feefoHeight = document.body.clientHeight;
   }
   //alert("newsize");
    //document.getElementById("feefopage").style.right = "3000px";
  
}          
            
   
   function FeefoSlideUpRun(){
        
   	FeefoSlider = document.getElementById('feefopage');
  	FeefoPageHeight = FeefoSlider.offsetHeight;
 	feefoPageUp = feefoHeight - FeefoPageHeight;
    	if (feefoPageUp < 0) feefoPageUp = 0;
     
   	if(FeefoSliderTop <= feefoPageUp){
   	   feefoSliding = false;
   	   FeefoSliderTop=feefoPageUp;
   	   FeefoSlider.style.top = feefoPageUp + "px";
   	   clearInterval(FeefoSliderIntervalId);
  	}else{
   	   FeefoSliderTop -= FeefoSlideSpeed;
   	   if(FeefoSliderTop < feefoPageUp)
   	      FeefoSliderTop = feefoPageUp;
   	   FeefoSlider.style.top = FeefoSliderTop + "px";
   	}
   }	
   
   function FeefoSlideDownRun(){
  	   FeefoSlider = document.getElementById('feefopage');
	   if(FeefoSliderTop >=feefoHeight || FeefoSliderTop < 0){
	      feefoSliding = false;
	      FeefoSliderTop=feefoHeight;
	      FeefoSlider.style.top = feefoHeight + "px";
              FeefoSlider.style.cssFloat = "right";
	      FeefoSlider.style.right="3000px";
	      clearInterval(FeefoSliderIntervalId);
	   }else{
	      FeefoSliderTop += FeefoSlideSpeed;
	      if(FeefoSliderTop > feefoHeight)
	         FeefoSliderTop = feefoHeight;
	      FeefoSlider.style.top = FeefoSliderTop + "px";
	   }

	}


function feefojsonfeed(obj) {


 
   htmltext = "";
  for (i = 0;i < obj.html.length;i++)
		htmltext+=obj.html[i];
   		htmltext = htmltext.replace(/¬/gi,"'");
 
  htmltext = htmltext.replace("'WINDOWOPEN'","\"window.open(this.href,'Feefo','width=800,height=600,scrollbars,resizable'); return false\"");

   //extract the stylesheet to put into the header for IE
  if (htmltext.indexOf("stylesheet") > 0){ 
     
     spos = htmltext.indexOf("stylesheet");
     apos = -1;
     tpos = 0;
     while (apos < spos){
     apos = htmltext.indexOf("<",apos + 1);
     	if (apos < spos) tpos = apos;
     }
     hrefpos = htmltext.indexOf("href=", tpos);
     quotemark = htmltext.substring(hrefpos + 5, hrefpos + 6);
      endpos = htmltext.indexOf(quotemark, hrefpos + 7);
      stylesheetURL = htmltext.substring(hrefpos + 6,endpos); 
  		var headID = document.getElementsByTagName("head")[0];         
  		var cssNode = document.createElement('link');
  		cssNode.type = 'text/css';
  		cssNode.rel = 'stylesheet';
  		cssNode.href = stylesheetURL;
  		cssNode.media = 'screen';
  		headID.appendChild(cssNode);
  		//note:  maybe I should remove the original line...
  }  
  feefopage1 = document.getElementById("feefopage");
  feefopage1.style.right = "3000px";
  feefopage1.style.top = feefoHeight + "px";
  feefopage1.innerHTML = htmltext;
   switch(feefoMethod){
	case "popup":
	  feefoFunction = 'FeefoPopup(false)';
	  break;
	case "lightbox":
	  feefoFunction = 'FeefoPopup(true)';
	  break;
	case "bottomrightsmooth":
   	  feefoFunction = 'FeefoSmooth("right")';
	  break;
	case "bottomleftsmooth":
  	  feefoFunction = 'FeefoSmooth("left")';
	  break;
       default:
          feefoFunction = 'FeefoPopup(false)';
    }
    setTimeout(feefoFunction, 500);

  
}	
 
  function FeefoSlide(){
      //this has to be here as it is called from the XSL sheets
      FeefoToggle(feefoMethod)
 }


 function FeefoToggle(method){
     feefoMethod = method;
	if(document.getElementById("feefopage").zIndex < 1000) {
		// Feefo CSS hasn't loaded yet - do not execute.
		return;
	}

  try { $('youtubevideo').hide(); } catch(err) { };

     if (document.getElementById("feefopage").innerHTML.length < 10){ //no page loaded, but length may be 5!?
      	feefojson();
      	return;
    }
   switch(method){
	case "popup":
	  FeefoPopup(false);
	  break;
	case "lightbox":
	  FeefoPopup(true);
	  break;
	case "bottomrightsmooth":
   	  FeefoSmooth("right");
	  break;
	case "bottomleftsmooth":
   	  FeefoSmooth("left");
	  break;
       default:
          FeefoPopup(false);
    }
 }   


 function FeefoSmooth(feefoPosition){
    	   if(feefoSliding)
	      return;
  	   FeefoSlider = document.getElementById('feefopage');
   	   feefoSliding = true;
	   if(FeefoSlider.style.right == "3000px"){
	      FeefoSliderTop = feefoHeight;
	      if (feefoPosition == "right"){
                FeefoSlider.style.cssFloat = "right";		
		FeefoSlider.style.right = "10px";
	      }else{
                FeefoSlider.style.right = "0";
	        FeefoSlider.style.cssFloat = "left";
		FeefoSlider.style.left = "10px";
	      }
	      FeefoSliderIntervalId = setInterval('FeefoSlideUpRun()', 20);
	   }   
	   else{
	      FeefoSliderIntervalId = setInterval('FeefoSlideDownRun()', 20);
	   }   
   }


	   
   function FeefoPopup(fade){
	
           
       if (document.getElementById("feefopage").innerHTML.length < 10){ //no page loaded, but length may be 5!?
 
      	feefojson();
      	return;
		}
      FeefoSlider = document.getElementById("feefopage");
		FeefoFade = document.getElementById("feefofade"); 
	   
 	   if(FeefoSlider.style.right == "3000px"){
 	   	newright = Math.round((feefoWidth - FeefoSlider.offsetWidth)/2);
 	   	newtop = Math.round((feefoHeight - FeefoSlider.offsetHeight)/2);
	      FeefoSlider.style.right = newright + "px";
	      FeefoSlider.style.top = newtop + "px";
              if (fade) FeefoFade.style.display = "block";
	      
	   }   
	   else{
	      FeefoSlider.style.right = "3000px";
	      FeefoFade.style.display = "none";
	   }   
   }
   
   
   
function feefoloadlogo(logon, feefooptions){
 
   
 	feefooptions = feefooptions.replace(/\&amp;/g,'&'); // in case the feefooptions are HTML encoded.
  	feefoproductcode = document.getElementById("feefoproduct");
   	feefoParams = "logon=" + logon;
        if (feefoproductcode){
	  if (/\S/.test(feefoproductcode.value)  && feefoproductcode.value != "service")
      	      feefoParams += "&vendorref=" +  escape(feefoproductcode.value) + "&mode=product";
	}
  	if (feefooptions.indexOf("method")>-1) {
		feefoMethod=feefooptions.substring(feefooptions.indexOf("method")+7,feefooptions.indexOf("&"));
		feefooptions=feefooptions.substring(feefooptions.indexOf("&",feefooptions.indexOf("method"))+1);
	}
	
   feefoParams = feefoParams + "&" + feefooptions;
  	
 		 
	feefotemplate = feefomaketemplate();
	feefotemplate=feefotemplate.replace("LOGOPARAMS", feefoParams);
	//feefotemplate=feefotemplate.replace("VIEWPARAMS", feefoParams);
	feefotemplate=feefotemplate.replace("FEEFOMETHOD", feefoMethod);
	feefotemplate=feefotemplate.replace("WINDOWOPEN","");
	document.write(feefotemplate);
	feefoGetWindowSize();
	
}	
   
function feefomaketemplate(){
	feefotemplate ='<LINK rel="stylesheet" type="text/css" href="' + feefoproto + '//www.feefo.com/logoscripts/feefoframe.css"/>';
	feefotemplate+='<div id="feefologo">';
	feefotemplate+='   <a id="feefologoa" href="javascript:FeefoToggle(&quot;FEEFOMETHOD&quot;);">';
	feefotemplate+='			<img src="' + feefoproto + '//www.feefo.com/feefo/feefologo.jsp?LOGOPARAMS"/>';
	feefotemplate+='		</a>';
	feefotemplate+='</div>';
	feefotemplate+='					<div id="feefopage">';
	feefotemplate+='					</div>';
	feefotemplate+='					<div id="feefofade"></div>';
 return feefotemplate;       
}    





function feefojson(){
   htmltext = feefoproto + "//www.feefo.com/feefo/xmlfeed.jsp?html=json&" + feefoParams +  ((feefoproto=="https:") ? "&protocol=https" : "");
   script = document.createElement('script'),
   head = document.getElementsByTagName('head')[0] || document.documentElement;
   script.src = htmltext;
    head.appendChild(script);
}   
   

