/*====================================
				    menu iteams
======================================*/
$('document').ready(function() {
$(".top-box .slidetabs a:last-child").addClass("last-child-tab");
$(".top-box-righ li:first-child").addClass("first-child");							 
$(".location-col:odd").addClass("location-right-side");
$(".pdf-middle-col li:last").addClass("pdf-last-link");
$("#navigation li:last").addClass("navigation-last-item");

$(".last-child-tab").click(function (event) {
	event.preventDefault();
});



inputReseter($('.field'), 'Name |');
inputReseter($('.field'), 'Email |');
inputReseter($('.field'), 'Company |');
inputReseter($('.field'), 'please type the characters to right  |');
inputReseter($('.message'), 'message |');

/*=========================================
			Animate an image
=========================================*/  
		$(function() {
					$('div.hover_block div.top').hover(function(){
						$(this).find('img').animate({top:'161px'},{queue:false,duration:500});
					}, function(){
						$(this).find('img').animate({top:'0px'},{queue:false,duration:500});
					});
					
						$('div.hover_block div.left').hover(function(){
						$(this).find('img').animate({left:'-161px'},{queue:false,duration:500});
					}, function(){
						$(this).find('img').animate({left:'0px'},{queue:false,duration:500});
					});
					
						$('div.hover_block div.right').hover(function(){
						$(this).find('img').animate({left:'161px'},{queue:false,duration:500});
					}, function(){
						$(this).find('img').animate({left:'0px'},{queue:false,duration:500});
					});
		});
		
/*========================================		
						Tabs
===========================================*/
// setup ul.tabs to work as tabs for each div directly under div.panes
$("ul.tabs").tabs("div.panes > div");		

var leftColT = $(".top-box .top-box-left").width();
var rightColT = $(".top-box .top-box-righ").width();
var slidetabsT = $(".top-box .slidetabs").width();
var spaceTabsT = (1000 - (leftColT + rightColT + slidetabsT)) / 2;

$(".slidetabs").css("padding-left", spaceTabsT);

$(document.body).bind('click', function (event) {
//var x = $($.pick(event.target, event.srcElement));

if(!($(event.target).parent('.pdf-download-box') == '.pdf-download-box')) {
	$(".pdf-download-box").hide();
}
});

$(".close-button").click(function (event) {
	event.preventDefault();
	$(".pdf-download-box").hide();
});

$(".download-pdf-doc").click(function (event) {
	event.preventDefault();
	$(".pdf-download-box").slideDown("slow");
});

$(".peter").hide();
$(".tres").hide();
$(".founderstab").click(function() {
  $(".tres").hide();
  $(".peter").hide();
});
$(".petertab").click(function() {
     $(".peter").show();
     $(".tres").hide();
});
$(".trestab").click(function() {
      $(".tres").show();
     $(".peter").hide();
});



/*=========================================
			Lists
=========================================*/


	listBreak('.studies-links', 6, '.main-content-box');
	$('#navigation li').children('.column').each(function(){
		
		$(this).wrap('<div class="wrap-column" />')	
	});
	$('#navigation li .wrap-column ul').each(function(){
		
		var i = 0;
  var $newUL;
  var $theColumn = $(this);
	
  var length = $theColumn.children('li').length;
  while(length > 11) {
    $newUL = $('<ul class="column2"></ul>');
    while(i < 12) {
        $theColumn.children('li').eq(11).appendTo($newUL)
        i++;
        length--;
    }
    $(this).parent().append($newUL);
    i = 0;
  }
	})

/*=========================================
		Add Class
=========================================*/
  var $topNava = $('ul:has(ul) > li a');
  $topNava.addClass('top-nav-a');

	
});

function listBreak(listName, listLengs, listItem){
  var i = 0;
  var $newUL;
  var $theColumn = $(listName);
  var length = $theColumn.children('li').length;
  while(length > listLengs) {
    $newUL = $('<ul class="' + $theColumn.attr('class') + '"></ul>');
    while(i < listLengs) {
        $theColumn.children('li').eq(6).appendTo($newUL)
        i++;
        length--;
    }
    $(listItem).append($newUL);
    i = 0;
  }
}

/*=========================================
							Fonts
=========================================*/

Cufon.replace('ul:has(ul) > li a', { hover: true, fontWeight: 200});




function inputReseter(jqObj, iniVal){
	$(jqObj).focus(function(){
		value = $(this).val();
		if( value == iniVal ){
		$(this).val('');
		}else{
		// user has ented input, do nothing
		}
	});
	$(jqObj).blur(function(){
		if($(this).val() === ''){
		$(this).val(iniVal);
		}else{
		// user has ented input, do nothing
		}
	});
}


/*=========================================
							Tooltips
=========================================*/
var $clickTo; 
var tooltipTimer;

$(window).load(function(){
	$clickTo = $('#clickTo'); 
	tooltipTimer = null;
	
	setTooltip($('#flowpanes .items div img'), "Click for next image."); //case study images
	setTooltip($('#flowtabs li a'), "Click for more work.");			 //nav dots
	setTooltip($('.pdf-box a img'), "Download case studies.");			 //pdf download link
});

function setTooltip(jObject, tooltipText) {
	jObject.hover(function(){
					  if (tooltipTimer == null) {
						  tooltipTimer = window.setTimeout(function(){
														$clickTo.html(tooltipText).show();
														tooltipTimer = null;
													},1000);
					  }
				  },
				  function(){
					  clearTimeout(tooltipTimer);
					  tooltipTimer = null;
					  $clickTo.hide();	
					  $clickTo.css({'left':-1000,'top':-1000});
				  });
	jObject.mousemove(function (event) {
						  var posleft = event.pageX;
						  var postop = event.pageY;
						  $clickTo.css({'left':posleft-20,'top':postop-18});
					  });
}




