var isExtended = 0;
var height = 310;
var width = 210;
var slideDuration = 800;
var opacityDuration = 500;


function extendContract(){
	
	if(isExtended == 0){
		
		sideBarSlide(0, height, 0, width);
		
		sideBarOpacity(0, 1);
	
		isExtended = 1;
		
		// make expand tab arrow image face left (inwards)
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');
		
	}
	else{
		
		sideBarSlide(height, 0, width, 0);
		
		sideBarOpacity(1, 0);
		
		isExtended = 0;
		
		// make expand tab arrow image face right (outwards)
		
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');
	}

}

function sideBarSlide(fromHeight, toHeight, fromWidth, toWidth){
		var myEffects = new Fx.Styles('sideBarContents', {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'height': [fromHeight, toHeight],
			 'width': [fromWidth, toWidth]
		});
}

function sideBarOpacity(from, to){
		var myEffects = new Fx.Styles('sideBarContents', {duration: opacityDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 'opacity': [from, to]
		});
}

function init(){
	// $('sideBarTab').addEvent('click', function(){extendContract()});
	$('sideBarTab').onclick=function(){extendContract()};
}


function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;




function change(tdid){


	

	if(tdid == "Image1"){
		document["Image1"].src= "widget_files/images/vuh_lge.png";
		document["Image2"].src= "widget_files/images/uh_sml.png";
		document["Image3"].src= "widget_files/images/pass_sml.png";
		document["Image4"].src= "widget_files/images/hap_sml.png";
		document["Image5"].src= "widget_files/images/vhap_sml.png";
		document["rant_and_rave_form"].score.value = 1;
	}

	if(tdid == 'Image2'){
		document["Image1"].src= "widget_files/images/vuh_sml.png";
		document["Image2"].src= "widget_files/images/uh_lge.png";
		document["Image3"].src= "widget_files/images/pass_sml.png";
		document["Image4"].src= "widget_files/images/hap_sml.png";
		document["Image5"].src= "widget_files/images/vhap_sml.png";

		document["rant_and_rave_form"].score.value = 2;
	}

	if(tdid == 'Image3'){
		document["Image1"].src= "widget_files/images/vuh_sml.png";
		document["Image2"].src= "widget_files/images/uh_sml.png";
		document["Image3"].src= "widget_files/images/pass_lge.png";
		document["Image4"].src= "widget_files/images/hap_sml.png";
		document["Image5"].src= "widget_files/images/vhap_sml.png";

		document["rant_and_rave_form"].score.value = 3;
	}

	if(tdid == 'Image4'){
		document["Image1"].src= "widget_files/images/vuh_sml.png";
		document["Image2"].src= "widget_files/images/uh_sml.png";
		document["Image3"].src= "widget_files/images/pass_sml.png";
		document["Image4"].src= "widget_files/images/hap_lge.png";
		document["Image5"].src= "widget_files/images/vhap_sml.png";

		document["rant_and_rave_form"].score.value = 4;
	}

	if(tdid == 'Image5'){
		document["Image1"].src= "widget_files/images/vuh_sml.png";
		document["Image2"].src= "widget_files/images/uh_sml.png";
		document["Image3"].src= "widget_files/images/pass_sml.png";
		document["Image4"].src= "widget_files/images/hap_sml.png";
		document["Image5"].src= "widget_files/images/vhap_lge.png";
		document["rant_and_rave_form"].score.value = 5;
	}

	if(tdid == 'mybox'){

		
		var score = document["rant_and_rave_form"].score.value;
		var comments = document["rant_and_rave_form"].comments.value;
		var ipStr = "web user";
		
		if(score == -1){
			alert("Please click on one of the smiley faces to select a score");
		}else if(comments == ""){
			alert("Please enter some comments");	
		}else{
			addScript("6", score, comments, ipStr);
			document.getElementById(tdid).innerHTML = "<p>Thanks for your comments.<br><br>We believe listening to what our customers have to say is an important part in delivering the very best services.<br><br>Please click on the 'have your say' tab to continue browsing<br><br>Powered by<br><a href=http://www.rantandrave.co.uk/feedback_solutions_feedback_widget.html target=_blank><img src=widget_files/images/rant-and-rave-logo.png></a><br>Click on the logo to use this on your website<br></p>";
		}
		
		//var ipStr = "web user";
		//addScript("6", score, comments, ipStr);
		//document.getElementById(tdid).innerHTML = "Thanks for your feedback";

	}

}

function changeImageOver(tdid){

	

	if(tdid == 'Image1'){
		document["Image1"].src= "widget_files/images/vuh_lge.png";
	}

	if(tdid == 'Image2'){
		 document["Image2"].src= "widget_files/images/uh_lge.png";
	}

	if(tdid == 'Image3'){
		document["Image3"].src= "widget_files/images/pass_lge.png";
	}

	if(tdid == 'Image4'){
		 document["Image4"].src= "widget_files/images/hap_lge.png";
	}

	if(tdid == 'Image5'){
		 document["Image5"].src= "widget_files/images/vhap_lge.png";

	}
}

function changeImageBack(tdid){

	

	if(tdid == 'Image1'){
		document["Image1"].src= "widget_files/images/vuh_sml.png";
	}

	if(tdid == 'Image2'){
		 document["Image2"].src= "widget_files/images/uh_sml.png";
	}

	if(tdid == 'Image3'){
		document["Image3"].src= "widget_files/images/pass_sml.png";
	}

	if(tdid == 'Image4'){
		 document["Image4"].src= "widget_files/images/hap_sml.png";
	}

	if(tdid == 'Image5'){
		 document["Image5"].src= "widget_files/images/vhap_sml.png";

	}
}


function addScript(comm_type, score, comments, address){


	var url="http://api.rantandrave.co.uk/RARSMSPostHandler/web/acceptWidgetAction.do"
	url=url+"?comm_type="+comm_type
	url=url+"&score="+score
	url=url+"&comments="+comments
	url=url+"&address="+address
	url=url+"&company_id="+164
	url=url+"&username=rapidefeedback"
	url=url+"&password=Yedre2"
	url=url+"&sid="+Math.random()

	var obj=new JSONscriptRequest(url);
	obj.buildScriptTag(); // Build the script tag
	obj.addScriptTag(); // Execute (add) the script tag


	var url2="HTTP://demo.rantandrave.co.uk/RantAndRaveCCI/CaptureItem.do"
	url2=url2+"?channel=3&userid=rapide&password=r4p1d3&Score="+score+"&Comments="+comments+"&Location=Website&Address=rapide.co.uk"
	url2=url2+"&sid="+Math.random()

	var obj2=new JSONscriptRequest(url2);
	obj2.buildScriptTag(); // Build the script tag
	obj2.addScriptTag(); // Execute (add) the script tag





}//end addScript

function loadWidget(){
document.write('<div id="sideBar"><a href="#" id="sideBarTab"><img src="widget_files/images/slide-button.png" alt="sideBar" title="Click here to have your say" /></a><div id="sideBarContents"><div id="sideBarContentsInner"><h2>&nbsp;&nbsp;<span>have</span><font color="#024a64">your</font><span>say</span></h2><div id="mybox"><p>We hope you enjoy your visit.<br>Click on a smiley face to let us know what you think.</p><table width="183" border="0" cellspacing="0" cellpadding="0"><tr><td><img src="widget_files/images/vuh_sml.png" name="Image1" id="Image1" style="border:none" onClick="change(\'Image1\')" /></td><td><img src="widget_files/images/uh_sml.png" name="Image2" id="Image2" style="border:none" onClick="change(\'Image2\')" /></td><td><img src="widget_files/images/pass_sml.png" name="Image3" id="Image3" style="border:none" onClick="change(\'Image3\')" /></td><td><img src="widget_files/images/hap_sml.png" name="Image4" id="Image4" style="border:none" onClick="change(\'Image4\')" /></td><td><img src="widget_files/images/vhap_sml.png" name="Image5" id="Image5" style="border:none" onClick="change(\'Image5\')" /></td></tr></table><p>Feel free to leave your comments below:</p><form id="rant_and_rave_form" name="rant_and_rave_form" method="post" action="http://api.rantandrave.co.uk/RARSMSPostHandler/web/acceptWidgetAction.do"><textarea name="comments" cols="" rows="" style="height:50px; width:180px;font-family:Arial, Helvetica, sans-serif; font-size:12px; margin-bottom:8px"></textarea><p>To find out more about Rapide<br /><strong>Please call 02476 011 910</strong></p><input type="hidden" name="score" value="-1"  /><img src="widget_files/images/submit.png" width="183" height="20" style="padding-top:8px" onclick="change(\'mybox\')" /> </form></div> </div> </div></div>');
}


window.addEvent('load', function(){init()});

