// useful javascript functions

// create a popup window - 21/03/09 - gavin taylor
function popup(link, windowname, width, height, scrollbars, status, resizable, location, toolbar, menubar)
{
	if(!window.focus) { return true; }

	//check if additional options are set
	if(windowname	== null) 	{ windowname 	= 'popup_window'; }
	if(scrollbars	== null) 	{ scrollbars 	= 'no'; }
	if(status			== null) 	{ status 			= 'no'; }
	if(resizable 	== null) 	{ resizable 	= 'no'; }
	if(location 	== null) 	{ location 		= 'no'; }
	if(toolbar 		== null) 	{ toolbar 		= 'no'; }
	if(menubar 		== null) 	{ menubar 		= 'no'; }

	var href;
	if(typeof(link) == 'string') { href=link; }
	else { href=link.href; }

	//window position
	var posleft = (screen.width - width) / 2;
	var postop 	= ((screen.height - height) / 2) / 2;

	newwindow = window.open(href, windowname, 'width=' + width + ', height=' + height + ',left=' + posleft + ',top=' + postop + ',scrollbars=' + scrollbars + ',status=' + status + ',resizable=' + resizable + ',location=' + location + ',toolbar=' + toolbar + ',menubar=' + menubar + '');
	if(window.focus) {newwindow.focus()}
	return false;
}

//creates an HTTP Request Object to be used as required
function getXmlHttpObject()
{
	if (window.XMLHttpRequest)
  {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
  }

	if (window.ActiveXObject)
  {
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
  }

	return null;
}

//display flash banner
function show_banner(banner_src, banner_width, banner_height)
{
	document.write('  	  <object width="' + banner_width + '" height="' + banner_height + '" id="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+location.protocol+'://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0">');
	document.write('            <param name="movie" value="' + banner_src + '" ');
	document.write('            <param name="quality" value="high" />');
	document.write('            <param name="wmode" value="transparent" />');
	document.write('            <param name="allowScriptAccess" value="always" />');
	document.write('            <embed src="' + banner_src + '" quality="high" type="application/x-shockwave-flash" pluginspage="'+location.protocol+'://www.macromedia.com/go/getflashplayer" width="' + banner_width + '" height="' + banner_height + '" wmode="transparent" allowScriptAccess="always"></embed>');
	document.write('      </object>');
}

function change_featured_tab(show_tab,tab_id,tab_links_id,no_of_tabs)
{
	//loop through all tabs
	for(i=1;i<=no_of_tabs;i++)
	{
		var tmp_tab_id 	= tab_id + i;
		var tab_class 	= '';
		var tab_content = 'none';

		if(i == show_tab)
		{
			tab_class 	= 'active';
			tab_content = 'block';
			$('ul > li#' +tmp_tab_id+ ' > a').addClass(tab_class);
		}else{
			$('ul > li#' +tmp_tab_id+ ' > a').removeClass('active');
		}

		//activate tab
		document.getElementById(tmp_tab_id).className = tab_class;


		//show tab content
		document.getElementById(tmp_tab_id + '_content').style.display = tab_content;
	}

	//update tabs class
	document.getElementById(tab_links_id).className = tab_id + show_tab + '_active';


	return false;
}

function rotate_gadget(gadget)
{
	var image = '';

	switch(gadget)
	{
		case 'speed':
			image = 'gadget_speed.jpg';
			url 	= '<?php echo DOMAIN_URL; ?>/cheetah.html';
			break;

		case 'seo':
			image = 'gadget_seo.jpg';
			url 	= '<?php echo DOMAIN_URL; ?>/seo-test.html';
			break;

		case 'security':
			image = 'gadget_security.jpg';
			url 	= '<?php echo DOMAIN_URL; ?>/proprotectme.html';
			break;
	}

	//update image
	document.getElementById('gadget_image').src = "/images/structure/homepage_banners/" + image;

	//update url
	document.getElementById('gadget_image_link').href = url;
}

// run the jcarousel
jQuery(document).ready(function() {
	jQuery('#mycarousel_accolade').jcarousel({
		auto:16,  // 15
		animation:'slow',
		scroll: 1,
		wrap: 'circular',
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_accolade},
		itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	});

	jQuery('#mycarousel_clients').jcarousel({
		auto:15, // 16
		animation:'slow',
		scroll: 1,
		wrap: 'circular',
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback_clients},
		itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
	});
 });


//accolades code
var mycarousel_itemList_accolade=[{img_url:"best_100_companies_2009.gif",award:"The Sunday Times - Best 100 Companies 2009",quote:"The best hosting provider to work for and rated in the top third of all UK businesses", url:"/business-awards.html"},{img_url:"tech_track_100_2009.gif",award:"The Sunday Times - Tech Track 100 Award 2009",quote:"The Sunday Times rates UKFast as 38th nationwide, 3rd in the North West and top in Manchester", url:"/business-awards.html"},{img_url:"best_company_2009.gif",award:"Best Company Award 2009",quote:"3 Star Rated Best Company", url:"/business-awards.html"}, {img_url:"business_of_the_year_2008.gif",award:"MEN Business of the Year 2008",quote:"UKFast beats very strong competition in its category of Manchester firms", url:"/business-awards.html"},{img_url:"ispa_best_business_customer_service_2009.gif",award:"ISPA Best Business Customer Service 2009",quote:"Superior level of support for UKFast customers", url:"/web-hosting-awards.html"},{img_url:"best_dedicated_hosting_2008.gif",award:"ISPA Best Dedicated Hosting 2008",quote:"Won due to UKFast's focus on customer care with a variety of secure hosting packages available", url:"/web-hosting-awards.html"}, {img_url:"ispa_corporate_social_award.gif",award:"ISPA Corporate Social Award 2009",quote:"UKFast's work in the area of Digital Inclusion is recognised", url:"/web-hosting-awards.html"}];function write_mycarousel_accolade(){document.write('<ul id="mycarousel_accolade" class="jcarousel-skin-tango"></ul>')}function mycarousel_itemVisibleInCallback_accolade(b,a,c,d,e){a=b.index(c,mycarousel_itemList_accolade.length);b.add(c,mycarousel_getItemHTML_accolade(mycarousel_itemList_accolade[a-1]))} function mycarousel_getItemHTML_accolade(b){var a;a='<a class="icon" style="background: url(/images/structure/ukfast_awards/'+b.img_url+');" title="'+b.award+'" href="'+b.url+'"></a>';a+="<h4>Our Accolades</h4>";return a=a+'<blockquote><a href="'+b.url+'" title="'+b.award+'">'+b.quote+"</a></blockquote>"};

//testimonials code
var mycarousel_itemList_clients=[{img_url:"sale_sharks.gif",award:"Sale Sharks",quote:"UKFast's continual vision gives us the confidence to keep developing this winning formula", url:"/client-stories.html"},{img_url:"printerland.co.uk.gif",award:"Printerland",quote:"We were delighted by UKFast\u2019s efficiency. Within days the site was functioning better than ever", url:"/client-stories.html"},{img_url:"client_logo_uktv.gif", award:"UKTV",quote:"UKFast is a unique, wonderful and fast service provider, and the wonderful account management has exceeding our expectations", url:"/client-stories.html"},{img_url:"caunce_ohara.gif",award:"Caunce O'Hara",quote:"UKFast's reliability is second-to-none. An ISP I would definitely recommend", url:"/client-stories.html"},{img_url:"printing.com.gif",award:"Printing.com",quote:"What truly sets UKFast apart is their customer care. UKFast go above and beyond the call of duty", url:"/client-stories.html"},{img_url:"foresite_spa.gif",award:"Foresite SPA",quote:"We performed time trials on our old server and the UKFast server and on average the UKFast machine was three times faster", url:"/client-stories.html"}, {img_url:"lets_stay_uk.gif",award:"Let's Stay Together",quote:"This extra performance of our site is clearly attributable to the speed of the UKFast dedicated, managed server", url:"/client-stories.html"},{img_url:"airwaves.gif",award:"Airwaves-Yamaha",quote:"The addition of UKFast, an award winning ISP, truly enhances our off track performance", url:"/client-stories.html"},{img_url:"all_join_on.gif",award:"All Join On",quote:"When I signed up to UKFast the effect was fantastic. The speed of the site was incredible and it showed in the amount of people signing up", url:"/client-stories.html"}, {img_url:"top_furniture.gif",award:"Top Furniture",quote:"UKFast has opened new levels of possibility for us as a business", url:"/client-stories.html"},{img_url:"ge_capital.gif",award:"GE Capital",quote:"We have been very impressed, in particular their ability to communicate technical terminology in an easy to understand manner", url:"/client-stories.html"},{img_url:"naked_scientists.gif",award:"The Naked Scientist",quote:"UKFast give us the scalable capacity to consistently make sure our science programmes are accessibly to our millions around the world", url:"/client-stories.html"}, {img_url:"jones_bootmakers.gif",award:"Jones the Bootmaker",quote:"UKFast manage to combine robust solutions, backed with excellent customer support, at a competitive price", url:"/client-stories.html"},{img_url:"history_channel.gif",award:"The History Channel UK",quote:"Flexible solutions and exceptional support, they make us feel like the only customer that matters", url:"/client-stories.html"}];function write_mycarousel_clients(){document.write('<ul id="mycarousel_clients" class="jcarousel-skin-tango"></ul>')} function mycarousel_itemVisibleInCallback_clients(b,a,c,d,e){a=b.index(c,mycarousel_itemList_clients.length);b.add(c,mycarousel_getItemHTML_clients(mycarousel_itemList_clients[a-1]))}function mycarousel_itemVisibleOutCallback(b,a,c,d,e){b.remove(c)} function mycarousel_getItemHTML_clients(b){var a;a='<a class="icon" style="background: url(/images/structure/client_logos/'+b.img_url+') no-repeat;" title="'+b.award+'" href="'+b.url+'"></a>';a+="<h4>Our Clients</h4>";return a=a+'<blockquote><a href="/client-stories.html" title="'+b.award+'">'+b.quote+"</a></blockquote><a class=\"read_more\" title=\"Read more client success stories\" href=\"http://www.ukfast.co.uk/client-stories.html\">Read more success stories</a>"};

//tabs.js
function ddtabcontent(a){this.tabinterfaceid=a;this.tabs=document.getElementById(a).getElementsByTagName("a");this.enabletabpersistence=true;this.hottabspositions=[];this.currentTabIndex=0;this.subcontentids=[];this.revcontentids=[];this.selectedClassTarget="link"}ddtabcontent.getCookie=function(a){a=new RegExp(a+"=[^;]+","i");if(document.cookie.match(a))return document.cookie.match(a)[0].split("=")[1];return""};ddtabcontent.setCookie=function(a,b){document.cookie=a+"="+b+";path=/"}; ddtabcontent.prototype={expandit:function(a){this.cancelautorun();var b="";try{if(typeof a=="string"&&document.getElementById(a).getAttribute("rel"))b=document.getElementById(a);else if(parseInt(a)!=NaN&&this.tabs[a].getAttribute("rel"))b=this.tabs[a]}catch(c){alert("Invalid Tab ID or position entered!")}b!=""&&this.expandtab(b);switch(a){case "tab_1_title":document.getElementById("tab").style.backgroundPosition="0px 0px";break;case "tab_2_title":document.getElementById("tab").style.backgroundPosition= "0px -26px";break;case "tab_3_title":document.getElementById("tab").style.backgroundPosition="0px -53px";break;case "tab_4_title":document.getElementById("tab").style.backgroundPosition="0px -79px";break;case "tab_5_title":document.getElementById("tab").style.backgroundPosition="0px -106px";break}},cycleit:function(a,b){if(a=="next")var c=this.currentTabIndex<this.hottabspositions.length-1?this.currentTabIndex+1:0;else if(a=="prev")c=this.currentTabIndex>0?this.currentTabIndex-1:this.hottabspositions.length- 1;typeof b=="undefined"&&this.cancelautorun();this.expandtab(this.tabs[this.hottabspositions[c]])},setpersist:function(a){this.enabletabpersistence=a},setselectedClassTarget:function(a){this.selectedClassTarget=a||"link"},getselectedClassTarget:function(a){return this.selectedClassTarget=="linkparent".toLowerCase()?a.parentNode:a},urlparamselect:function(a){return window.location.search.match(new RegExp(a+"=(\\d+)","i"))==null?null:parseInt(RegExp.$1)},gototab:function(a){switch(a){case "1":tab.expandit("tab_1_title"); break;case "2":tab.expandit("tab_2_title");break;case "3":tab.expandit("tab_3_title");break;case "4":tab.expandit("tab_4_title");break;case "5":tab.expandit("tab_5_title");break}},expandtab:function(a){var b=a.getAttribute("rel"),c=a.getAttribute("rev")?","+a.getAttribute("rev").replace(/\s+/,"")+",":"";this.expandsubcontent(b);this.expandrevcontent(c);for(c=0;c<this.tabs.length;c++)this.getselectedClassTarget(this.tabs[c]).className=this.tabs[c].getAttribute("rel")==b?"selected":"";this.enabletabpersistence&& ddtabcontent.setCookie(this.tabinterfaceid,a.tabposition);this.setcurrenttabindex(a.tabposition)},expandsubcontent:function(a){for(var b=0;b<this.subcontentids.length;b++){var c=document.getElementById(this.subcontentids[b]);c.style.display=c.id==a?"block":"none"}},expandrevcontent:function(a){for(var b=this.revcontentids,c=0;c<b.length;c++)document.getElementById(b[c]).style.display=a.indexOf(","+b[c]+",")!=-1?"block":"none"},setcurrenttabindex:function(a){for(var b=0;b<this.hottabspositions.length;b++)if(a== this.hottabspositions[b]){this.currentTabIndex=b;break}},autorun:function(){this.cycleit("next",true)},cancelautorun:function(){typeof this.autoruntimer!="undefined"&&clearInterval(this.autoruntimer)},init:function(a){var b=ddtabcontent.getCookie(this.tabinterfaceid),c=-1,d=unescape(self.document.location.hash.substring(1)),f=d;if(d!="")f=d-1;this.automodeperiod=a||0;for(a=0;a<this.tabs.length;a++){this.tabs[a].tabposition=a;if(this.tabs[a].getAttribute("rel")){var e=this;this.hottabspositions[this.hottabspositions.length]= a;this.subcontentids[this.subcontentids.length]=this.tabs[a].getAttribute("rel");this.tabs[a].onclick=function(){e.expandtab(this);e.cancelautorun();return false};if(this.tabs[a].getAttribute("rev"))this.revcontentids=this.revcontentids.concat(this.tabs[a].getAttribute("rev").split(/\s*,\s*/));if(f==a||this.enabletabpersistence&&c==-1&&parseInt(b)==a||!this.enabletabpersistence&&c==-1&&this.getselectedClassTarget(this.tabs[a]).className=="selected")c=a}}c!=-1?this.expandtab(this.tabs[c]):this.expandtab(this.tabs[this.hottabspositions[0]]); if(parseInt(this.automodeperiod)>500&&this.hottabspositions.length>1)this.autoruntimer=setInterval(function(){e.autorun()},this.automodeperiod)}};


function default_rating(curval,default_message)
{
	for (i=1;i<=5;i++)
	{
		//reset image
		document.getElementById('rating' + i).style.backgroundPosition = '-203px -1px';

		//update if required
		if(i <= curval)
		{
			document.getElementById('rating' + i).style.backgroundPosition = '-220px -1px';
		}
	}
	document.getElementById('pre_message').innerHTML = default_message;
}

function update_rating(rating_value,media)
{
	switch(rating_value)
	{
		case 1:
			message = 'Poor';
			break;

		case 2:
			message = 'Nothing special';
			break;

		case 3:
			if (media == 'video')
			{
				message = 'Worth watching';
			}
			else
			{
				message = 'Worth reading';
			}
			break;

		case 4:
			message = 'Pretty cool';
			break;

		case 5:
			message = 'Excellent!';
			break;

		default:
			message = 'unknown rating selected';
			rating_value = 0;
			break;
	}

	//update stars
	for (i=1;i<=5;i++)
	{
		//reset image
		document.getElementById('rating' + i).style.backgroundPosition = '-203px -1px';

		//update if required
		if(i<=rating_value)
		{
			document.getElementById('rating' + i).style.backgroundPosition = '-237px -1px';
		}
	}

	//update message
	document.getElementById('pre_message').innerHTML = message;
}

function submit_rating(rating_value,user_id,session_id,media_id,media_type)
{
	//create AJAX request variable
	var http = getXmlHttpObject();

	//remove javascript calls from stars to prevent future submission
	for (i=1;i<=5;i++)
	{
		document.getElementById('rating' + i).onmouseover	= null;
		document.getElementById('rating' + i).onmouseout	= null;
		document.getElementById('rating' + i).onclick 		= null;
		document.getElementById('rating' + i).title 		  = 'Thanks for rating!';
	}

	//submit rating details
	http.open("POST", "/scripts/process_rating.php", true);
	var parameters = "user_id=" + user_id + "&session_id=" + session_id + "&media_type=" + media_type + "&media_id=" + media_id +"&media_rating=" + rating_value;
	http.onreadystatechange=function()
	{
		var message = 'Unable to process your request!';
		if(http.readyState == 4)
		{
			if (http.status==200)
			{
				//update message
				message = http.responseText;

				//rewrite message as too long for the pre_message container
				if(message=='Thanks for rating!') { message = 'Thank you.'; }

				//update cookie
				update_cookie('ukfast_' + media_type + '_ratings',media_id);
			}
		}
		document.getElementById('pre_message').innerHTML = message;
	}
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", parameters.length);
	http.send(parameters);
}

function update_cookie(cookie_name,cookie_value)
{
	var data = '';

	//check if cookie exists
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(cookie_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + cookie_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			data = unescape(document.cookie.substring(c_start,c_end)) + "|";
		}
	}

	//update cookie data
	data = data + cookie_value;

	//create new cookie to store data in
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+300);
	document.cookie = cookie_name + "=" + data + ";path=/;expires=" + exdate.toGMTString();
}

function toggle_faq(id)
{
	if (document.getElementById('faq_'+ id).style.display == 'none')
	{
		document.getElementById('faq_'+ id).style.display = '';
	}
	else
	{
		document.getElementById('faq_'+ id).style.display = 'none';
	}
}

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('display', 'block');
}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('display', 'none');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('.navigation_level_1 > li').bind('mouseover', jsddm_open)
   $('.navigation_level_1 > li').bind('mouseout',  jsddm_timer)});

document.onclick = jsddm_close;
