var browser, verStr = navigator.appVersion, app = navigator.appName, version = parseFloat(verStr);

function test_browser () {
  if ((app.indexOf('Netscape') != -1) && version >= 5) {
    browser = "netscape";
  }
  else if ((app.indexOf('Microsoft') != -1) && version >= 4) {
    browser = "ie";
  }
}

var body_content = new Array("bodycontent", "preloader");

function show_sub(show_which_sub, mode) {  

  if (show_which_sub != "") {
   if (document.getElementById(show_which_sub).style.display == 'block') {
			document.getElementById(show_which_sub).style.display = 'none';
		}
		else {
			document.getElementById(show_which_sub).style.display = 'block';
			if(mode == "video"){
				var tmp_top = parseInt(document.getElementById(show_which_sub).style.top);
				var scr_top = document.getElementById("select_video_div").scrollTop;
				document.getElementById(show_which_sub).style.top = (tmp_top - scr_top)+ "px";
			}
		}
  }

}

function hide_sub(which_sub, mode) {
  document.getElementById(which_sub).style.display = 'none';
	if(mode == "video"){
		var tmp_top = parseInt(document.getElementById(which_sub).style.top);
		var scr_top = document.getElementById("select_video_div").scrollTop;
		document.getElementById(which_sub).style.top = (tmp_top + scr_top)+ "px";
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

test_browser();

var active_menu = "";
function display_menu(menu_id) {

  if (active_menu != "") {
    if (active_menu != menu_id) {
      document.getElementById(active_menu).style.display = "none";
    }
  }
  document.getElementById(menu_id).style.display = "block";
  active_menu = menu_id;

}

function display_rec(row_id) {

  if (document.getElementById(row_id).style.display == "none") {
    document.getElementById(row_id).style.display = "block";
  }
  else {
    document.getElementById(row_id).style.display = "none";
  }

}

function update_flash() {

  objects = document.getElementsByTagName("object");
  for (var i = 0; i < objects.length; i++)  {
      objects[i].outerHTML = objects[i].outerHTML;
  }

}

function char_count(eid, maxlen, max_lines) {

  var inputstr;
  var strlen;
  var charleft;
  var numcr;
  var temp = new Array();

  if (document.getElementById(eid).value != "") {
    inputstr = document.getElementById(eid).value;
    strlen = inputstr.length;

    if (strlen > maxlen) {
      document.getElementById(eid).value = document.getElementById(eid).value.substring(0,maxlen);
      charleft = 0;
      alert("Exceeds maximum number of characters!");
    }
    else {
      charleft = maxlen - strlen;
    }

    document.getElementById('charleft' + eid).innerHTML = charleft + " / " + maxlen;

  }

  if (max_lines > 0) {

    var temp2 = document.getElementById(eid).value.split('\r\n');
    var temp_val = "";
    counter = 0;
    if (temp2.length > max_lines) {
      alert("Exceeds maximum number of lines!");
      for (i = 0; i < max_lines; i++) {
        temp_val = temp_val + temp2[i];
        if (i < (max_lines - 1)) {
          temp_val = temp_val + "\n";
        }
      }
      document.getElementById(eid).value = temp_val;
    }

  }

}

var active_box ="livebox";
function publishbox(current_box)
{
  if(active_box !="" && active_box != current_box){
    document.getElementById(active_box).style.display = "none";
  }
    document.getElementById(current_box).style.display = "block";
    active_box = current_box;
}

function submit_form(form_name, cmd) {
  if (document.getElementById('cmd')) {
    document.getElementById('cmd').value = cmd;
  }
  document.getElementById(form_name).submit();
  for (i = 0; i < document.forms.length; i++) {
    var frm = document.forms[i];
    for(x=0; x< frm.length; x++){
      if (frm.elements[x].type == "button") {
        frm.elements[x].disabled = true;
      }
    }
  }
}

active_faq = "";
function show_answer(faq_id) {

  if (active_faq != "") {
    document.getElementById(active_faq).style.display = "none";
  }
  document.getElementById(faq_id).style.display = "block";
  active_faq = faq_id;

}

active_left_nav = "";
function show_left_nav(left_nav_id) {

  if (active_left_nav != "") {
    document.getElementById(active_left_nav).style.display = "none";
  }
  document.getElementById(left_nav_id).style.display = "block";
  active_left_nav = left_nav_id;

}

var active_menu   = "";
var active_level  = "";
var active_top    = "";

function show_menu(which_menu, menu_level, top_menu) {

  if (menu_level == active_level) {
    document.getElementById(active_menu).style.display = "none";
  }
  if (menu_level < active_level) {
    if(document.getElementById(active_top)){
      document.getElementById(active_top).style.display = "none";
      document.getElementById(active_menu).style.display = "none";
    }
  }

  if (document.getElementById(which_menu).style.display != "block") {
    document.getElementById(which_menu).style.display = "block";
    active_menu = which_menu;
    active_level = menu_level;
    active_top = top_menu;
  }

}
function blurQ(r){
    var q = document.getElementById('comment_form');
    if(q.value == ''){
        q.style.color = '#a3a396';
        q.value = r;
    }
}

function focusQ(r){
    var q = document.getElementById('comment_form');
    q.style.color = '#a3a396';
    if(q.value == r) q.value = '';
}
function check_source() {
  document.getElementById('other_source').style.display = "none";
  if (document.getElementById('source').value == "Other") {
    document.getElementById('other_source').style.display = "block";
  }
}

function load_presenter (presenter) {
  var presenter_ids = new Array();
  presenter_ids["Aaron"]    = 114;
  presenter_ids["Bethany"]  = 106;
  presenter_ids["Briony"]   = 107;
  presenter_ids["Candy"]    = 116;
  presenter_ids["Carolyne"] = 117;
  presenter_ids["Cindy"]    = 108;
  presenter_ids["Eli"]      = 119;
  presenter_ids["Hanna"]    = 118;
  presenter_ids["Helen"]    = 120;
  presenter_ids["James"]    = 122;
  presenter_ids["John"]     = 113;
  presenter_ids["Karolina"] = 123;
  presenter_ids["Lara"]     = 127;
  presenter_ids["Laura"]    = 125;
  presenter_ids["Lilian"]   = 126;
  presenter_ids["Shaun"]    = 128;
  presenter_ids["Tina"]     = 105;
  presenter_ids["Wil"]      = 104;
  presenter_ids["Jordie"]   = 254;
  presenter_ids["Lisa"]     = 311;
  presenter_ids["Susie"]    = 312;
  presenter_ids["Sara D"]   = 313;
  presenter_ids["Cedric"]   = 314;
  presenter_ids["Mark"]     = 315;
  presenter_ids["Justin"]   = 316;
  presenter_ids["Karen"]    = 317;
  presenter_ids["Madeline"] = 318;
  presenter_ids["Kate"]     = 319;
  presenter_ids["Steve"]    = 320;
  presenter_ids["Peter"]    = 321;
  presenter_ids["Chloe"]    = 322;
  presenter_ids["Nathan"]   = 323;
  presenter_ids["Sarah L"]  = 324;
 
  presenter_id = presenter_ids[presenter];
  
  filmtime.play({id:presenter_id, align:'bl', preload:'20'});

}

active_presenter = "";
function update_player(presenter) {
  if (active_presenter != "" && active_presenter != presenter) {
    document.getElementById(active_presenter).innerHTML = "reinitializing player...";
    var so = new SWFObject("/flash/audio_player.swf", active_presenter, "150", "35", "6", "#ffffff");
    so.addParam("wmode", "transparent");
    so.addVariable("presenter", active_presenter);
    so.write(active_presenter);
  }
  active_presenter = presenter;
}

var display = "hide";
function expand_content(){

	if(display == "show"){			
		$('#hidden_content').slideToggle('normal', function(){					
			display = "hide";
			//document.getElementById("read_more").innerHTML = "read more";
		});
		
	}else{		
		$('#hidden_content').slideToggle('normal');
		scroll_to_content();
		display = "show";
		//document.getElementById("read_more").innerHTML = "close";
	}
}
function scroll_to_content(){
	var destination = $("#hidden_content").offset().top;	
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1000);	
}

var embed_src = "";

function build_embed_code(){
  var embed_width  = document.getElementById('embed_width').value;
  var embed_height = document.getElementById('embed_height').value;

  if(embed_width == "" || embed_height == ""){
    alert("Please enter a valid size");
    return false;
  }

  var str = '<iframe width="' + embed_width + '" height="' + embed_height + '" src="' + embed_src + '" frameborder="0"></iframe>';

  document.getElementById('embed_code').value =  str;
  document.getElementById('embed_code').select();
}

function hd_toggle(){
	if(document.getElementById('chk_hd').checked){
		document.getElementById('player').style.display = "none";
		document.getElementById('player_hd').style.display = "block";
	}else{
		document.getElementById('player_hd').style.display = "none";
		document.getElementById('player').style.display = "block";
	}
}
var active_banner = 0;
var active_banner_class = "showreel";
function show_banner(banner_index, banner_class){
	if(banner_class != undefined){
		$('#banner_' + active_banner).hide();
		$('#tab_' + active_banner).removeClass(active_banner_class + '_a');		
		
		$('#tab_' + banner_index).addClass(banner_class + '_a');		
		$('#banner_' + banner_index).fadeIn(200);
		active_banner = banner_index;
		active_banner_class = banner_class;
	}else{
		$('#banner_' + active_banner).hide();		
		$('#tab_' + active_banner).removeClass('active');
				
		$('#tab_' + banner_index).addClass('active');
		$('#banner_' + banner_index).fadeIn(200);
		active_banner = banner_index;		
	}
	
}

/* testimonial animation start */
var testimonials = new Array();
var active_testimonial = 0;

function testimonial_slide() {	
	$('#tlink_' + active_testimonial).removeClass('rect_1');
	$('#tdiv_' + active_testimonial).stop().animate({ left: "-960" }, 400);
	
	if(active_testimonial == testimonials[testimonials.length - 1]){
		active_testimonial = 0;
	}else{
		active_testimonial++;
	}
	
	$('#tlink_' + active_testimonial).addClass('rect_1');
	$('#tdiv_' + active_testimonial).stop().css({left:'960px'});
	$('#tdiv_' + active_testimonial).animate({ left: "0" }, 400);

}

var interval;
function auto_slide(){		
	var num_testimonials = parseInt(document.getElementById("num_testimonials").value);	
	for(i = 0; i < num_testimonials; i++){
		testimonials[i] = i;
	}
	interval = setInterval("testimonial_slide()", 7000);	
}
function show_testimonial(testimonial_index){	 
	interval = clearInterval(interval);
	if(testimonial_index != active_testimonial){
		$('#tlink_' + active_testimonial).removeClass('rect_1');
		$('#tdiv_' + active_testimonial).stop().animate({ left: "-960" }, 400);
		active_testimonial = testimonial_index;
		$('#tlink_' + active_testimonial).addClass('rect_1');
		$('#tdiv_' + active_testimonial).stop().css({left:'960px'});
		$('#tdiv_' + active_testimonial).animate({ left: "0" }, 400);
	}
	interval = setInterval("testimonial_slide()", 7000);
}
/* testimonial animation end */

function fill_text(el_id, el_text){
	val = document.getElementById(el_id).value
	if(val == ""){
		document.getElementById(el_id).value = el_text;
	}
}
function showmap(address, company_name, map_div, x, y) {				
	var myLatlng = new google.maps.LatLng(x, y);
	var myOptions = {
		zoom: 15,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}

	var map = new google.maps.Map(document.getElementById(map_div), myOptions);
	var marker = new google.maps.Marker({
			map: map, 
			position: myLatlng,
			title:company_name
	});
	
	var infowindow = new google.maps.InfoWindow({																				
		content: "<strong>" + company_name + "</strong><br />" + address
	});
	
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map,marker);
	});							
}
function shimmer(el_id){
	$('#' + el_id).animate({backgroundPosition:'100px 0'},500,function(){ $(this).removeAttr('style'); });
}
function validate_website(){
	if(document.getElementById("website_address").value == "" || document.getElementById("website_address").value == "www.yourwebsite.com"){
		alert("Please enter your website address.");
		return false;	
	}
	return true;
}
function submit_enquiry(){
	var cta_name  = document.getElementById("cta_name").value;
	var cta_email = document.getElementById("cta_email").value;
	var cta_comment = document.getElementById("cta_comment").value;
	if(cta_name == ""){
		alert("Please enter your name");
		return false;
	}
	if(cta_email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
		alert("Please enter a valid email address.")
		return false;
	}
	if(cta_comment == ""){
		alert("Please enter your enquiry");
		return false;
	}
	
	var url   = "/ajax/cta_contact.ajx.php?email=" + urlencode(cta_email) + "&name=" + urlencode(cta_name) + "&comments=" + urlencode(cta_comment);
	query = "";
	document.getElementById("cta_contact").innerHTML = "Sending...";		
	tmp_http_req = new init_post_request();
	enquiry_req  = tmp_http_req.fn_request;
	enquiry_req.onreadystatechange = function(){
		if (enquiry_req.readyState == 4 || enquiry_req.readyState == "complete")  {  			    			
			data = enquiry_req.responseText;			
			document.getElementById("cta_contact").innerHTML = data;						
		}	
	};		
	post_request(enquiry_req, url, query);
}
