// JavaScript Document

/*--------------------------------------------------*/
/* Twitter*/
/*--------------------------------------------------*/

function twitterCallback2(C){
	var A=[];for(
				 var D=0;D<C.length;D++){
		var E=C[D].user.screen_name;var B=C[D].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g,
		function(F){
			return'<a href="'+F+'" target="_blank">'+F+"</a>"}).replace(/\B@([_a-z0-9]+)/ig,
			function(F){
				return F.charAt(0)+'<a href="http://www.twitter.com/'+F.substring(1)+'">'+F.substring(1)+"</a>"});A.push("<li><div class='twitter_date'><p class='sidebar_font twitterdate'>"+relative_time(C[D].created_at)+'</p></div><p class="sidebar_font twitter"><span>'+B+"</span></p></li>")}document.getElementById("twitter_update_list").innerHTML=A.join("")
			}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + " " + values[5] + " " + values[3];
  var parsed_date = new Date();
  parsed_date.setTime(Date.parse(time_value));  
  var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
	'Sep', 'Oct', 'Nov', 'Dec');
  var m = parsed_date.getMonth();
  var postedAt = '';
  postedAt = months[m];
  postedAt += " "+ parsed_date.getDate();
  postedAt += ","
  postedAt += " "+ parsed_date.getFullYear();
  return postedAt;
}

/*--------------------------------------------------*/
/* Testimonials - Slider*/
/*--------------------------------------------------*/

$(document).ready(function(){	
  $("#testimonials_slider").easySlider();
});

/*--------------------------------------------------*/
/* Slideshow - Gallery View*/
/*--------------------------------------------------*/

$(document).ready(function(){		
  $('#photos').galleryView({
	panel_width: 644,
	panel_height: 282,
	frame_width: 106,
	frame_height: 66,
	overlay_color: 'transparent',
	transition_speed: 500,
	transition_interval: 6000,
	background_color: 'transparent',
	border: 'none',
	nav_theme: 'slideshow',
	easing: 'easeInQuad',
	pause_on_hover: true
  });
  $('.boxgrid.captionfull').hover(function(){
  $(".cover", this).stop().animate({top:'214px'},{queue:false,duration:160});
	  }, function() {
  $(".cover", this).stop().animate({top:'320px'},{queue:false,duration:160});
  });
});

/*--------------------------------------------------*/
/* Show/Hide Panel*/
/*--------------------------------------------------*/

$(document).ready(function(){
	$(".btn_slide").click(function(){
		$("#theme_bottom_bar").slideToggle("slow");
		/*$(this).toggleClass("active"); return false;*/
	});
});

/*--------------------------------------------------*/
/* Mailing List - Form Validation*/
/*--------------------------------------------------*/

$(document).ready(function(){
	$('#mailinglist_form').ajaxForm(function(data) {
		if (data==0){$('.ml-error').hide();$('.ml-success').fadeIn("slow");}
		else if (data==1){$('.ml-success').hide(); $('.ml-error').fadeIn("slow");}
	});
});

/*--------------------------------------------------*/
/* Slideshow - Cycle*/
/*--------------------------------------------------*/
$(function() {
	$('.splash_showcase').cycle({fx:'fade', timeout:27000, speed:1000, pager:'#splash_control'});
});

/*--------------------------------------------------*/
/* Showcase - Fading Caption*/
/*--------------------------------------------------*/

$(document).ready(function() {
$('.showcase_items div.highlight').hover(function() {
   $(this).children(".title").fadeIn(400);},
   function() {$(this).children(".title").fadeOut(800);
});
});

/*--------------------------------------------------*/
/* Contact - Form Focus & Validation*/
/*--------------------------------------------------*/

$(document).ready(function() {
	$('input.textfield').addClass("input_textfield");
	$('input.textfield').focus(function() {
		$(this).removeClass("input_textfield").addClass("input_textfield_focus");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input.textfield').blur(function() {
		$(this).removeClass("input_textfield_focus").addClass("input_textfield");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('input.textfield_subject').addClass("input_textfield_subject");
	$('input.textfield_subject').focus(function() {
		$(this).removeClass("input_textfield_subject").addClass("input_textfield_subject_focus");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('input.textfield_subject').blur(function() {
		$(this).removeClass("input_textfield_subject_focus").addClass("input_textfield_subject");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('textarea').addClass("input_textfield_message");
	$('textarea').focus(function() {
		$(this).removeClass("input_textfield_message").addClass("input_textfield_message_focus");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('textarea').blur(function() {
		$(this).removeClass("input_textfield_message_focus").addClass("input_textfield_message");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('#contact_form').ajaxForm(function(data) {
		if (data==2){$('.contact-error').hide();$('.contact-success').fadeIn("slow");$('#contact_form').resetForm();}
		else if (data==3){$('.contact-success').hide(); $('.contact-error').fadeIn("slow");}
	});
});	

/*--------------------------------------------------*/
/* Showcase - Fancybox*/
/*--------------------------------------------------*/

$(document).ready(function() {
  $("a.single").fancybox({
	  imageScale:false,
	  centerOnScroll:false,
	  padding:10,
	  overlayOpacity:0.6
	});
});

/*--------------------------------------------------*/
/* Mailing List - Form*/
/*--------------------------------------------------*/

$(document).ready(function() {
function initOverLabels () {
  if (!document.getElementById) return;  	

  var labels, id, field;

  // Set focus and blur handlers to hide and show 
  // LABELs with 'overlabel' class names.
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
	
    if (labels[i].className == 'overlabel') {

      // Skip labels that do not have a named association
      // with another field.
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }

      // Change the applied class to hover the label 
      // over the form field.
      labels[i].className = 'overlabel-apply';

      // Hide any fields having an initial value.
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }

      // Set handlers to show and hide labels.
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };

      // Handle clicks to LABEL elements (for Safari).
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };

    }
  }
};

function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-9999px' : '0px';
      return true;
    }
  }
}

window.onload = function () {
  setTimeout(initOverLabels, 50);
};
});
