var _siteRoot='',_root='';
$(function(){
 
 slider.init();

});


var slider={
 num:-1,
 cur:0,
 cr:[],
 al:null,
 at:8*1000,
 ar:true,
 init:function(){
  if(!slider.data || !slider.data.length)
   return false;

  var d=slider.data;
  slider.num=d.length;
  var pos=Math.floor(Math.random()*1);//slider.num);
  for(var i=0;i<slider.num;i++){
   $('#'+d[i].id).css({left:((i-pos)*1000)});
   $('#slide-nav').append('<a id="slide-link-'+i+'" href="#" onclick="slider.slide('+i+');return false;" onfocus="this.blur();">'+(i+1)+'</a>');
   
  }

  $('img,div#slide-controls',$('div#slide-holder')).stop().show();
  slider.text(d[pos]);
  slider.on(pos);
  slider.cur=pos;
  window.setTimeout('slider.auto();',slider.at);
 },
 auto:function(){
  if(!slider.ar)
   return false;

  var next=slider.cur+1;
  if(next>=slider.num) next=0;
  slider.slide(next);
 },
 slide:function(pos){
  if(pos<0 || pos>=slider.num || pos==slider.cur)
   return;

  window.clearTimeout(slider.al);
  slider.al=window.setTimeout('slider.auto();',slider.at);

  var d=slider.data;
  for(var i=0;i<slider.num;i++)
   $('#'+d[i].id).stop().animate({left:((i-pos)*2000)},1000,'swing');
  
  slider.on(pos);
  slider.text(d[pos]);
  slider.cur=pos;
 },
 on:function(pos){
  $('#slide-nav a').removeClass('on');
  $('#slide-nav a#slide-link-'+pos).addClass('on');
 
 },
 text:function(di){
  slider.cr['a']=di.client;
  slider.cr['b']=di.desc;
  slider.ticker('#slide-client span',di.client,0,'a');
  slider.ticker('#slide-desc',di.desc,0,'b');
 },
 ticker:function(el,text,pos,unique){
  if(slider.cr[unique]!=text)
   return false;

  ctext=text.substring(0,pos)+(pos%2?'-':'_');
  $(el).html(ctext);

  if(pos==text.length)
   $(el).html(text);
  else
   window.setTimeout('slider.ticker("'+el+'","'+text+'",'+(pos+1)+',"'+unique+'");',30);
 }
};

var mc={
 flag:0,
 auto_open:true,
 auto_play:true,
 pulse_go:false,
 hov_html:'<div id="mcdivhover"></div>',
 init:function(){
  if(!$('#media-centre').length)
   return;

  if(mc.auto_open && !get_cookie('id_visited')){
   $(window).load(function(){
     setTimeout(function(){mc.toggle(0);},500);
   });
  }
  set_cookie('id_visited','true',365,'index.html');
  if(!get_cookie('id_pclicked')){
   mc.pulse_go=true;
   mc.pulse(1);
  }
  $('#media-centre').css({top:-419});
  $('#media-centre-holder').css({height:0}).show();
  $('#media-centre-tabs a:first').addClass('on');
  $('#'+$('#media-centre-tabs a:first').attr('rel')).show();

  $('#media-centre-tabs a').click(function(){
   $('#media-centre-tabs a').removeClass('on');
   $(this).addClass('on');

   $('div#media-centre-videos div').hide();
   $('#'+$(this).attr('rel')).show();
  });

  $('div#media-centre-videos div p.video').hover(function(){
   $(this).append(mc.hov_html);
   var o=$(this).find('img').offset();
   $('#mcdivhover').show();
  },function(){
   $('#mcdivhover').remove();
  }).click(function(){
   $('div#media-centre-videos div p.video').removeClass('playing');
   $(this).addClass('playing');
   mc.play($(this).find('span.file').html());
   if($(this).is('.ontwerp'))
    $('#ontwerp-tag').stop().show();
   else
    $('#ontwerp-tag').fadeOut();
  });

  $('div#media-centre-videos div p.news').hover(function(){
   $(this).addClass('hover');
  },function(){
   $(this).removeClass('hover');
  }).click(function(){
   location.href=$(this).find('span.url').html();
  });
 },
 toggle:function(pulse_set){
  if(mc.flag) mc.pause();
  if(pulse_set && !get_cookie('id_pclicked')){
   mc.pulse_go=false;
   set_cookie('id_pclicked','true',365,'index.html');
  }
  $('.mca').toggleClass('t');

  $('#media-centre-holder').stop().animate({height:mc.flag?0:419},1000,'swing');
  $('#media-centre').stop().animate({top:mc.flag?-419:0},1000,'swing',function(){try{
   if(mc.flag && mc.auto_play){
    var f=$('div#media-centre-videos div p.video:first');
    $('div#media-centre-videos div p.video').removeClass('playing');
    f.addClass('playing');
    mc.play($(this).find('span.file').html());
    if(f.is('.ontwerp')) $('#ontwerp-tag').stop().show();
    else $('#ontwerp-tag').fadeOut();
    mc.auto_play=false;
   }
  }catch(e){}});
  if($('#pusher').length){
   $('.tml_open').hide();
   $('#pusher div').stop().animate({height:mc.flag?0:419},1000,'swing',function(){
    $('.tml_open').each(function(){
     $(this).show().css({top:$(this).offset().top+((mc.flag?1:-1)*120)});
    });
   });
  }
  set_cookie('id_mc',mc.flag?'closed':'open',30,'index.html');
  mc.flag=!mc.flag;
 },
 play:function(src){
  if(!document.getElementById || !document.getElementById('objectmc'))
   return false;
  document.getElementById('objectmc').playVideo(_siteRoot+src);
 },
 pause:function(){
  if(!document.getElementById || !document.getElementById('objectmc'))
   return false;
  document.getElementById('objectmc').pauseVideo();
 },
 pulse:function(s){
  if(!mc.pulse_go)
   $('#mc-pulse').fadeOut(750);
  else if(s)
   $('#mc-pulse').slideDown(750,function(){mc.pulse(0);});
  else
   $('#mc-pulse').fadeOut(750,function(){mc.pulse(1);});
 },
 checkHash:function(){
  if(!document.getElementById || !document.getElementById('objectvp'))
   return false;
  var id=location.hash.replace(/[^0-9]/,'');
  if(id!=''){
   setTimeout(function(){
    document.getElementById('objectvp').moveId(id);
    load_comments(id);
   },750);
  }
 },
 live:function(){
  mc.toggle(0);
  if(mc.flag){
   window.setTimeout(function(){mc.play($('p.video:first').attr('rel'));},1100);
   window.setTimeout('mc.live();',42*1000);
  }else
   window.setTimeout('mc.live();',2.5*60*1000);
 }
};

var cmap={
 is_open:false,
 gmap:false,
 form_id:'contact-form',
 map_id:'contact-map',
 time:750,
 open:function(){
  if(cmap.is_open) return false;
  $('#'+cmap.form_id).fadeOut(cmap.time,function(){
   $('#'+cmap.map_id).slideDown(cmap.time,function(){
    if(GBrowserIsCompatible() && !cmap.gmap){
     cmap.gmap=true;
     var map=new GMap2(document.getElementById('gmap'));
     var ll=new GLatLng(51.465772,-0.298347);
     map.setCenter(ll,13);
     map.addOverlay(new GMarker(ll));
     map.addControl(new GSmallMapControl());
     map.addControl(new GMapTypeControl());
     cmap.gdir=new GDirections(map,document.getElementById('cmap_dir'));
     GEvent.addListener(cmap.gdir,'error',cmap.handleErrors);
    }
   });
  });
  cmap.is_open=true;
 },
 close:function(){
  if(!cmap.is_open) return false;
  $('#'+cmap.map_id).fadeOut(cmap.time,function(){$('#'+cmap.form_id).slideDown(cmap.time);});
  cmap.is_open=false;
 },
 directions:function(to){
  cmap.gdir.load('from: Kew Road, Richmond, UK to: '+to,{'locale':'en_UK'});
 },
 handleErrors:function(){
  if(cmap.gdir.getStatus().code==G_GEO_UNKNOWN_ADDRESS)
   alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + cmap.gdir.getStatus().code);
  else if (cmap.gdir.getStatus().code==G_GEO_SERVER_ERROR)
   alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + cmap.gdir.getStatus().code);
  else if (cmap.gdir.getStatus().code==G_GEO_MISSING_QUERY)
   alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + cmap.gdir.getStatus().code);
  else if (cmap.gdir.getStatus().code==G_GEO_BAD_KEY)
   alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + cmap.gdir.getStatus().code);
  else if (cmap.gdir.getStatus().code==G_GEO_BAD_REQUEST)
   alert("A directions request could not be successfully parsed.\n Error code: " + cmap.gdir.getStatus().code);
  else alert("An unknown error occurred.");
 }
};

function toolbox_save(){
 if($('#popup-toolbox').length){
  var bg=$('#popup-toolbox img.on').attr('src').split('bg/bg')[1].split('-thumb')[0];
  var colour=$('#popup-toolbox a.on').attr('id');

  if($('#toolbox-remember').is(':checked')){
   $.get(_root,{set_bg:bg,set_colour:colour},function(){});
  }
  $('#popup-toolbox').fadeOut();
  $('li.toolbox').removeClass('toolbox-open');
 }
}

var client_root=_root+'client/';
function client_login(form){
 $.post(client_root,{user:form.client_user.value,pass:form.client_pass.value},
  function(data){
   if(data=='0') $('#popup-client p.error').stop().show();
   else location.href=client_root;
  }
 );
}
function cms_login(form){
 $.post(_siteRoot+'ajax-login.php',{user:form.cms_user.value,pass:form.cms_pass.value},
  function(data){
   if(data=='0') $('#popup-cms p.error').stop().show();
   else location.href=_root+'wp-admin/';
  }
 );
}

Array.prototype.in_array=function(v){
 for(var i in this)
  if(this[i]==v)
   return true;
 return false;
}
Array.prototype.remove=function(s){
 for(i=0;i<this.length;i++)
  if(s==this[i])
   this.splice(i,1);
}

var star_off=_siteRoot+'images/star-off.png',star_on=_siteRoot+'images/star-on.png',star_html='<p class="stars" rel="%s%">';
for(var i=1;i<6;i++)star_html+='<img src="'+star_off+'" alt="" id="star_%s%_'+i+'" onmouseover="feedback_stars(this,\'over\',\'%s%\','+i+');" onmouseout="feedback_stars(this,\'out\',\'%s%\','+i+');" onclick="feedback_stars(this,\'click\',\'%s%\','+i+');" width="15" height="15" />';star_html+='<input type="hidden" id="rating_%s%" name="rating_%s%" value="-1" /></p>';

var fb_html='<div id="feedback_div"><form action="'+_siteRoot+'feedback.php" method="post"><a href="#" id="fb_close" onclick="feedback_close();return false;" onfocus="blur();">Close</a>'+
'<div class="rate"><p>This page</p><p class="indent">Design:</p>'+star_html.replace(/%s%/gi,'page_design')+'<p class="indent">Content:</p>'+star_html.replace(/%s%/gi,'page_content')+'<p class="indent">Ease of use:</p>'+star_html.replace(/%s%/gi,'page_ease')+'<p class="indent">Overall:</p>'+star_html.replace(/%s%/gi,'page_overall')+'</div>'+
'<div class="rate"><p>Whole site</p><p class="indent">Design:</p>'+star_html.replace(/%s%/gi,'site_design')+'<p class="indent">Content:</p>'+star_html.replace(/%s%/gi,'site_content')+'<p class="indent">Ease of use:</p>'+star_html.replace(/%s%/gi,'site_ease')+'<p class="indent">Overall:</p>'+star_html.replace(/%s%/gi,'site_overall')+'</div>'+
'<div class="form"><label>Name: <input type="text" name="name" value="" class="text" /></label><label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email: <input type="text" name="email" value="" class="text" /></label><label class="ta">Comments:<br /><textarea name="comments" cols="10" rows="5"></textarea></label><br style="clear:both;" /><input type="submit" name="submit" class="button" value="" /></div>'+
'</form></div>';

function feedback(obj){
 if(fb_html!=''){
  jQuery(document.body).append(fb_html);
  fb_html='';
  _offset=jQuery(obj).offset();
  jQuery('#feedback_div').css({'left':_offset.left-jQuery('#feedback_div').width()+jQuery(obj).width()-30,'top':_offset.top-240});
 }
 if(jQuery('#feedback_div').is(':visible')) jQuery('#feedback_div').fadeOut(250);
 else jQuery('#feedback_div').stop().show();
}
function feedback_close(){
 if(jQuery('#feedback_div').is(':visible'))
  jQuery('#feedback_div').fadeOut(250);
}
jQuery(document).click(function(e){
 if(jQuery('#feedback_div').is(':visible')){
  var obj=e.target,ids=[];
  while(obj.parentNode){
   ids[ids.length]=obj.id;
   obj=obj.parentNode;
  }
  if(!ids.in_array('feedback_div') && !ids.in_array('feedback_a'))
   jQuery('#feedback_div').fadeOut(250);
 }
});
var fb_r=[];
function feedback_stars(obj,b,s,r){
 switch(b){
  case 'over' :
   for(var i=1;i<6;i++){
    if(i<=r) jQuery('#star_'+s+'_'+i).attr('src',star_on);
    else jQuery('#star_'+s+'_'+i).attr('src',star_off);
   }
   break;
  case 'out' :
   for(var i=1;i<6;i++){
    if(typeof fb_r[s]!='undefined' && i<=fb_r[s]) jQuery('#star_'+s+'_'+i).attr('src',star_on);
    else jQuery('#star_'+s+'_'+i).attr('src',star_off);
   }
   break;
  case 'click' :
   fb_r[s]=r;
   jQuery('#rating_'+s).val(r);
   break;
 }
}

function load_comments(id){
 $('#comment_post_ID').val(id);
 $('#video-comments').html('<p>Loading comments&hellip;</p>');

 $.getJSON(_siteRoot+'json-comments.php?id='+id,function(data){
  var html='';
  $('#video-comments').html('<p>There are no comments for this video.</p>');
  $.each(data,function(){
   html+='<div class="comment"><p class="author colour">'+this.comment_author+' says:</p><p class="date">'+this.date+'</p><p class="message">'+this.comment_content+'</p></div>';
   html+='<div class="hr"></div>';
	});
  if(html!='')
   $('#video-comments').html(html);
 });
}

// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07


