var Blogposition = 0;
var BlogElementWidth = 452;
var TestimonialsPosition = 0;
var TestimonialsWidth = 313;
var HideTrialFormOnMouseout = true;
var topCount = 0;
var jsoncount = 0;

window.addEvent('domready', function () {


    $('signUpBg2').setStyle('top', '0px');
    $('signUp2').setStyle('top', '-62px');

    //TopCurrentLinks();
    //HelloMsgs();
    //Testimonials();
    //Homevideo();
    //megaIcons2();
    
   feefopanelIntervalId = setInterval('ShiftLogosLeft()', 20);
   feefolatestfeedbackIntervalId = setInterval('latestfeedback()',10000);//new feedback every 10 secs
   topImageId = setInterval('RotateTopImages()', 8000);

    var panel1, panel2, panel3, yellowtab1, yellowtab2, yellowtab3, yellowtab4;
    megaIcon(panel1, '#panel1',"howitworksover",127);
    megaIcon(panel2, "#panel2","costsandpackagesover",127);
    megaIcon(panel3, "#panel3","benefitsover",127);
    megaIcon(yellowtab1, "#yellowtab1", "yellowover1",127);
   megaIcon(yellowtab2, "#yellowtab2", "yellowover2",127);
   megaIcon(yellowtab3, "#yellowtab3", "yellowover3",127);
   megaIcon(yellowtab4, "#yellowtab4", "yellowover4",127);
    megaIcon(yellowtab1, "#yellowtab5", "yellowover5",127);
   megaIcon(yellowtab2, "#yellowtab6", "yellowover6",127);
   megaIcon(yellowtab3, "#yellowtab7", "yellowover7",127);
   megaIcon(yellowtab4, "#yellowtab8", "yellowover8",127);
   
   
    
    return;
    $$('.titleText').setStyle('opacity', 0);
    $$('.homeBlogItems').getLast().morph({ 'margin-top': '6px', 'height': '71px' });

    $$('.homeBlogItems').each(function (el, i, a) {
        el.addEvents({
            'mouseenter': function (e) {

                el.getFirst('.titleText').morph({ 'opacity': 0.9 });
            },
            'mouseleave': function (e) {
                el.getFirst('.titleText').morph({ 'opacity': 0 });
            }
        });
    });
});

function RotateTopImages(){

		cycle = (topCount /4);
		topCount = topCount + 1;
		remainder = topCount - 4 * Math.floor(cycle);
		nextremainder = remainder +1;
		if (nextremainder == 5)
		   nextremainder = 1;
		fade("topimage" + remainder, "topimage" + nextremainder);
		   
		//document.getElementById("homeFlashBanner").style.background='url("../images/pc' + remainder + '.png") no-repeat scroll 0 0 transparent';
}		
				


function megaIcon(panelvar, panelname, iconname,$height) {
	
	
  $displaymode="absolute";
  $(iconname).set('morph', { duration: '200' });
  $(iconname).setStyle('display', 'none');
 
	iconNameImg = "#" + iconname + " img";

  $$(iconNameImg).set('morph', { duration: '300' });
  $$(iconNameImg).morph({ 'position': $displaymode, 'width': '0px', 'height': '0px', 'top': '40px', 'left': '120px' });

  panelvar = $$(panelname);
  panelvar.each(function (el, i, a) {
  		el.addEvents({ 'mouseenter': function () {
  			iconNameImg = "#" + iconname + " img";
 			$(iconname).morph({ 'display': 'block' });
  			$$(iconNameImg).morph({ 'width': '244px', 'height': '130px', 'top': '0px', 'left': '0px' });
 		},
 			'mouseleave': function () {
 				iconNameImg = "#" + iconname + " img";
				$$(iconNameImg).morph({ 'position': $displaymode, 'width': '50px', 'height': '80px', 'top': '40px', 'left': '120px' });
 				$(iconname).morph({ 'display': 'none' });
 			}
 		});
 	});
  
}
 

function TwitterTab(){
	document.getElementById("latestnewstab").style.left = "160px";
	document.getElementById("latestnewstab").style.zIndex = "3";
	document.getElementById("twittertab").style.left = "60px";
	document.getElementById("news").style.left = "-2000px";
	document.getElementById("twitter").style.left = "-5px";
	document.getElementById("twitter").style.top = "2px";
}

function LatestNewsTab(){
	document.getElementById("latestnewstab").style.left = "60px";
	document.getElementById("latestnewstab").style.zIndex = "2";
	document.getElementById("twittertab").style.left = "160px";
	document.getElementById("news").style.left = "0px";
	document.getElementById("twitter").style.left = "-2000px";
}

function HelloMsgs() {

    $("feefoInnerMover").set('morph', { duration: '700', transition: 'expo:out' });

    $('helloNext').addEvent("click", function () {
        Blogposition++;

        // Hide Button If Needed
        if (Blogposition == $$(".helloGadgets").length - 1) {
            $('helloNext').setStyle("opacity", 0);
        }

        // Show Back Button If Needed
        if (Blogposition > 0) {
            $('helloBack').setStyle("opacity", 1);
        }

        $('feefoInnerMover').morph({ "left": -BlogElementWidth * Blogposition });
    });

    $('helloBack').setStyle("opacity", 0);

    $('helloBack').addEvent("click", function () {
        Blogposition--;

        // Hide Button If Needed
        if (Blogposition == 0) {
            $('helloBack').setStyle("opacity", 0);
        }

        // Show Back Button If Needed
        if (Blogposition < $$(".helloGadgets").length - 1) {
            $('helloNext').setStyle("opacity", 1);
        }

        $('feefoInnerMover').morph({ "left": -BlogElementWidth * Blogposition });

    });
}



function runVideo(){
	//swfobject.embedSWF("resources/flash/Feefo_video.swf", "homeFlashBanner", "980", "316", "9.0.0", "expressInstall.swf");
	 Homevideo();
		//swfobject.embedSWF("http://www.youtube.com/v/Jy_sMMKSpko?fs=1&amp;hl=en_GB", "homeFlashBanner", "745", "317", "9.0.0", "expressInstall.swf");
}

var TimeToFade = 1000.0;

function fade(eid1, eid2)
{
  var element1 = document.getElementById(eid1);
  if(element1 == null)
    return;
   
  if(element1.FadeState == null)
  {
    if(element1.style.opacity == null 
        || element1.style.opacity == '' 
        || element1.style.opacity == '1')
    {
      element1.FadeState = 2;
    }
    else
    {
      element1.FadeState = -2;
    }
  }
    
  if(element1.FadeState == 1 || element1.FadeState == -1)
  {
    element1.FadeState = element1.FadeState == 1 ? -1 : 1;
    element1.FadeTimeLeft = TimeToFade - element1.FadeTimeLeft;
  }
  else
  {
    element1.FadeState = element1.FadeState == 2 ? -1 : 1;
    element1.FadeTimeLeft = TimeToFade;
    setTimeout("animateFade(" + new Date().getTime() + ",'" + eid1 + "','" + eid2 + "')", 33);
  }  
}


function animateFade(lastTick, eid1, eid2)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element1 = document.getElementById(eid1);
  var element2 = document.getElementById(eid2);

  if(element1.FadeTimeLeft <= elapsedTicks)
  {
    if (element1.FadeState == 1){
    		element1.style.opacity = 1;
    		element2.style.opacity = 0;
    		element1.style.filter = "alpha(opacity=100)";
    		element2.style.filter = "alpha(opacity=0)";
    		element1.FadeState = 2;
    		element2.FadeState = -2;
    }else{
    	   element1.style.opacity = 0;
    	   element2.style.opacity = 1;
   		element1.style.filter = "alpha(opacity=0)";
    		element2.style.filter = "alpha(opacity=100)";
    		element1.FadeState = -2;
    		element2.FadeState = 2;
     }	   
    return;
  }
 
  element1.FadeTimeLeft -= elapsedTicks;
 
  var newOpVal = element1.FadeTimeLeft/TimeToFade;
  if(element1.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element1.style.opacity = newOpVal;
  element2.style.opacity = 1 - newOpVal;
  element1.style.filter = 'alpha(opacity=' + (newOpVal*100) + ')';
  element2.style.filter = 'alpha(opacity=' + ((1-newOpVal) * 100) + ')';
  setTimeout("animateFade(" + curTick + ",'" + eid1 + "','" + eid2 + "')", 33);
}



function Homevideo() {

    var FeefoYouTubeURL = '<object width="979" height="316"><param name="movie"value="http://www.youtube.com/v/Jy_sMMKSpko?fs=1&amp;hl=en_GB">' +
    '</param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always">' +
    '</param><embed src="http://www.youtube.com/v/Jy_sMMKSpko?fs=1&amp;hl=en_GB" type="application/x-shockwave-flash" allowscriptaccess="always"' +
    ' allowfullscreen="true" width="979" height="390"></embed></object>';

    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
        //alert('Iphone Detected');
        $('homeFlashBanner').set('html', FeefoYouTubeURL);
        $('signUpBg2').setStyle('display', 'none');

    }
    else {

        if (Browser.Plugins.Flash.version == 0) {
            alert('You do not have flash player installed on your machine, Please install the latest version of flash to see the contents properly. Thanks');
        }
        else {
        	  
             signUpInvisible()
            //alert('I am first screen');
            obj = new Swiff('/feefo/resources/flash/Feefo_video.swf', {
           //obj = new Swiff('/feefo/resources/flash/Feefo-First-Screen.swf', {

                width: 980,
                height: 320,
                wmode:"opaque",
                params: {
                    wmode: 'transparent',
                    bgcolor: '#ff0000'
                },
                container: $('homeFlashBanner')
            });
        }
    }
    
    function HomevideoLast() {


        //alert('I am last screen');

        obj = new Swiff('/../flash/Feefo-End-Screen.swf', {

            width: 980,
            height: 320,
            params: {
                wmode: 'transparent',
                bgcolor: '#ff0000'
            },
            container: $('homeFlashBanner')
        });
    }
}

function DropDownForm() {
     $('signUpBg2').morph({ 'top': '0px' });
	$('signUp2').setStyle('height', '0px');
}

function signupButtonGoesUp() {

	 $('signUp2').setStyle('top', '-62px');
    $('signUpBg2').morph({ 'top': '-960px' });
}

function signUpVisible() {

    $('signUp2').setStyle('top', '0px');
	$('signUp2').setStyle('height', '29px');
}

function signUpInvisible() {

    $('signUp2').morph({ 'top': '-62px' });
    $('signUpBg2').morph({ 'top': '-960px' });
}


function TopCurrentLinks() {

    var url = document.location.toString().split("/");

    var SelectedTopMenuLink = 0;

    $$(".topLinks").each(function (e, i, a) {
        if (i == SelectedTopMenuLink) {
            e.addClass("currentTopMenu");

        }
    });
}



function ShiftLogosLeft(){
	clientlist = document.getElementById("clientlogolist");
	currentleft = clientlist.offsetLeft - 1;
	if (currentleft > -4820)
	  clientlist.style.left = (currentleft-1) + "px";
	else
	   clientlist.style.left = "0px";
	   
}

function feefojsonfeed(obj) {

  	htmltext= ""; 
   for (i = 0;i < obj.html.length;i++)
		htmltext+=obj.html[i];
  
   document.getElementById("commenttablewrapper").innerHTML = htmltext;

}    
    
 	   
function latestfeedback(){
jsoncount = 1;
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    response=xmlhttp.responseText;
    document.getElementById("commenttablewrapper").innerHTML = response;
    return;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
xmlhttp.open("POST","/feefo/latestfeedback.jsp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("sessionid=" + jsoncount);
}
 

function feefojson(){
	//count has to be increased to force IE not to cache the results...
	jsoncount= jsoncount + 1;
	
   htmltext = "http://www.feefo.com/feefo/latestfeedback.jsp?json=true&count=" + jsoncount;
   script = document.createElement('script'),
   head = document.getElementsByTagName('head')[0] || document.documentElement;
   script.src = htmltext;
   head.appendChild(script);
}   


function newsubscriber(){
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    response=xmlhttp.responseText;
    alert("Thank you for registering");
    return;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
xmlhttp.open("POST","/feefo/contact.jsp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("context=news&email=" + document.getElementById("subscribeemail").value);



}


