var link_temp = "_images/nav/word_cloud_indentify.gif";
	 
     
$(document).ready( function(){



  /*************************************************************************/
		  /* Newsletter functions*/
		  
		  /*Show the form */
		  
		  function show_ln_sub_form(){
			   
			   $('#form_wrapper').css('display' , 'block');
			    
		  }
		  
		  
		  function close_ln_sub_form(){
			   
			   $('#form_wrapper').css('display' , 'none');
			   	
				
		  }
		  
		  
	 $('#news_close').click(function(event){
			   
			   event.preventDefault();
			   close_ln_sub_form();
			   
		  });
	 
	  $('#form_mask').click(function(){
			   
			   
			   close_ln_sub_form();
			   
		  });
	  
	  $('#news_header_link a').click(function(e){
		  
		  e.preventDefault();
		  show_ln_sub_form();
		  
	 });
		  




//custom font

Cufon.replace('.formata_light', { hover: true});



//$("#content_column_B").css('overflow-y', 'hidden');
//$("#content_column_C").css('overflow-y', 'hidden');

$('div#bottom_wrapper').css('overflow', 'hidden');

if($.browser.msie){
  
$('div.staff_show').click(function(e){
  e.preventDefault();
  
  var temp_location = $(this).find('a').attr('href');
  
  window.location = temp_location;
  
  return false;
  });
  

  
  
}


/////////////////////////////////////////////////////////////////////////////////////////////
////////////////dropmenucode
////////////////////////////////////////////////////////////////////////////////////////////

  
function megaHoverOver(){
    
	$(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
   
}
//On Hover Out
function megaHoverOut(){
  
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}




//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 50, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 100, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};


$("ul#nav_list li.no_java_css").removeClass("no_java_css");

$("ul#nav_list li div.sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#nav_list li").hoverIntent(config); //Trigger Hover intent with custom configurations
  
  
  

		
/////////////////////////////////////////////////////////////////////////////////////////////
// Slider Javascript

  

//setup the styles dynamically with jquery
		/*var true_width = parseInt($('li.lqn_slide').innerWidth()) + parseInt($('li.lqn_slide').css('margin-left'));
		
		var frameWidth = $('#slide_frame').innerWidth();
		var pageWidth = Math.round((Math.round(frameWidth / true_width)) /2);
		
		
		
        $('#slide_container').css('width', true_width *{$food_list_count});*/
		
		$('#slide_frame').css('overflow-x' , 'hidden');
		$('#slide_container').css('top' , '1.5em');
		
		$('#slide_frame').not('.no_slider').serialScroll({
		items:'li',
		prev:'#nav_left_arrow',
		next:'#nav_right_arrow',
		step: 4,
		offset:0, //when scrolling to photo
		start:0, //as we are centering it, start at the 1st
		duration:700,
		force:false,
		stop:true,
		lock:true,
		cycle:true, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: false //click on the images to scroll to them
		
	});
        
        
		
		
		
	

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Staff Selector Function
	 


	 
	 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// Img swap function for porfolios
function portImgHoverOver(){
  
  if(typeof $(this).find("img").attr('src') == "undefined"){return false;}
  
  
  var findImgArray = $(this).find("img").attr('src').split('/'); //capture the image for processing
  var imgFilePath = '';
  
  for(var x = 0; x < findImgArray.length-1; x++){//rebuild the image path not including the image name
	
	imgFilePath = imgFilePath + findImgArray[x] + "/";
	
  }
  
  
  
  var imgSplitArray = findImgArray[findImgArray.length-1].split('_'); //capture the image for processing
  
  
  
  if(imgSplitArray.length == 3){
	
	var imgName = imgSplitArray[0] + '_' + imgSplitArray[1]; //capture the image for processing
	
  }
  else{
	var imgName = imgSplitArray[0]; //capture the image for processing
  }
  
  var hoverImgName = imgName + "_hover.gif";
  
  $(this).find("img").attr('src', imgFilePath + hoverImgName);
  
  
  return true; 
}
//On Hover Out
function portImgHoverOut(){

  if(typeof $(this).find("img").attr('src') == "undefined"){return false;}

    if(link_temp == $(this).find('a').attr('href')){return false;}
	
  var findImgArray = $(this).find("img").attr('src').split('/'); //capture the image for processing
  var imgFilePath = '';
  
  for(var x = 0; x < findImgArray.length-1; x++){//rebuild the image path not including the image name
	
	imgFilePath = imgFilePath + findImgArray[x] + "/";
	
  }
  
  var imgSplitArray = findImgArray[findImgArray.length-1].split('_'); //capture the image for processing
  var imgName = imgSplitArray[0]; //capture the image for processing
  
  if(imgSplitArray.length == 3){
	
	var imgName = imgSplitArray[0] + '_' + imgSplitArray[1]; //capture the image for processing
	
  }
  else{
	var imgName = imgSplitArray[0]; //capture the image for processing
  }
  
  
  var hoverImgName = imgName + "_norm.gif";
  
  $(this).find("img").attr('src', imgFilePath + hoverImgName);


return true;
}



//Set custom configurations
var portImg_config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 25, // number = milliseconds for onMouseOver polling interval
     over: portImgHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 25, // number = milliseconds delay before onMouseOut
     out: portImgHoverOut // function = onMouseOut callback (REQUIRED)
};

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////

//////Staff hover Icons


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// Img swap function for porfolios

function staffImgHoverOver(){
  

  
  $(this).find("img.staff_icon_img_hover").show();
  
  
   
}
//On Hover Out
function staffImgHoverOut(){

    $(this).find("img.staff_icon_img_hover").hide();
 
}



//Set custom configurations
var staffImg_config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 25, // number = milliseconds for onMouseOver polling interval
     over: staffImgHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 25, // number = milliseconds delay before onMouseOut
     out: staffImgHoverOut // function = onMouseOut callback (REQUIRED)
};




$("div.staff_show").hoverIntent(staffImg_config); //Trigger Hover intent with custom configurations



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


$("div#slider li.nav_slide").hoverIntent(portImg_config); //Trigger Hover intent with custom configurations

// Slider Click functions


/*$('li.nav_slide a').click(function(){
  window.location = $(this).attr('href');
});*/

$('li.nav_slide a.portfolio_click').click(function(e){
  e.preventDefault;
  
  
  
  var link = $(this).attr('href');
  
  var splitTemp = link.split('-');
  
  var docketNumber = splitTemp[2];
  
  var docketType = splitTemp[1];
  
  ajaxDocketRequest(docketNumber,docketType);
  
  
  
  return false;
});


//ajax calls on functions
var bindbehaviours = function(scope){
  
  /*$('a.subitem_click', scope).click(function(e){
  e.preventDefault;
  
  alert('hello');
  
  return false;
  });*/
  
  $('a.start_click', scope).click(function(e){
	e.preventDefault();
	
	
	  $('a.subitem_click:eq(0)').trigger('click');
	
	return false;});

  $('a.subitem_click', scope).nyroModal({ modal: false, sizes: { h: 500, w: 500, minH: 500, minW: 500, wMargin:0, hMargin:0 }, elts: { bg: '#ffffff'}, callbacks:{
  
  afterShowCont: function(nm){$('div.nyroModalDom').css('padding', '0px');},
  beforeShowCont: function(nm){}
  } });
  
};


bindbehaviours(this);

$('a.lightbox_click').nyroModal();
 
 
$('a.login_click').click(function(e){
  e.preventDefault();
  
  
  show_ln_sub_form();
  
  
  return false;
  });

//////////////////////////////////////////////////////////////////////////////////////////
// for creating new like and send buttons

function ajaxCreateNewButtons(url){
  
			var elem = $(document.createElement("fb:like"));
			var elem2 = $(document.createElement("fb:send"));
            
			elem.attr("href", url);
			elem.attr("font", 'arial');
			elem.attr("show_faces", 'false');
			elem.attr("width", '55');
			elem.attr("layout", 'box_count');
			
			elem2.attr("href", url);
			elem2.attr("font", 'arial');
			
            $("div#fb_like").empty().append(elem).append(elem2);
			FB.XFBML.parse(document.getElementById('fb_like'));
}
	 
//////////////////////////////////////////////////////////////////////////////////////////
//	my jquery functions
// ajax image function

function ajaxDocketRequest(docket_ID, docket_TYPE){
  
  
  				$.post('_inc/ajax_portfolio_functions.php',
                    {
                    docket_id: docket_ID,
					docket_type: docket_TYPE
					
                    
                    },
                    function(xml) {
					  
					  ajaxCreateNewButtons('http://www.3h.ca/work-' + docket_TYPE + '-' +  docket_ID);

					  var lrg_path = "_images/portfolio/large/";
					  var preview_path = "_images/portfolio/preview/";
					  var small_path = "_images/portfolio/very_small/";
					 $('div.portfolio_pre_frame').html("<a href='' class='start_click'><img src='" + preview_path + $('docketSample', xml).text() + "' alt='" + $('docketCampaign', xml).text() + "'/></a>");
                          
						  $('div.mandate_header').html($('docketCompany', xml).text());
						  $('div.campaign_subhead').html($('docketCampaign', xml).text());
						  $('div.mandate_copy').html($('docketMandate', xml).text());
						  $('div.target_copy').html($('docketTarget', xml).text());
						  $('div.featured_copy').html($('docketFeatured', xml).text());
						  $('div.team_copy').html($('docketTeam', xml).text());
						  $('div.featured_items_links').html("");
						  
						  var item_count = 0;
						  var first_click = "";
						  $(xml).find("docketSubItem").each(function(){
					
							//reminder do similar function
					
							//alert($(this).text());
							//alert($(this).attr('itemid'));
							item_count++;
							
							
							if(item_count == 0){
							  first_click = "first_click";
							}else{
							  first_click = "";
							}
							
							switch($(this).find('docketSubItemmedia').text()){
					  
								  case "picture":
								 
									
									
									$('div.featured_items_links').append("<a href='" + lrg_path +  $(this).find('docketSubItemfile').text()  + "' rel='gal' class='subitem_click " + first_click + "' title='" + $('docketCompany', xml).text() + ":" + $('docketCampaign', xml).text() + "'><img src='" + small_path + $(this).find('docketSubItempreview').text() + "' alt='" + $('docketCompany', xml).text() + " " + item_count + "' /></a>");
								  
								  break;
								
								  case "website"://subitem_click_vid
									
									var var_name_replace = new String($('docketCompany', xml).text());
									var_name_replace = var_name_replace.toLowerCase();
									
									var_name_replace = var_name_replace.replace(' & ','_');
									var_name_replace = var_name_replace.replace(' ','_');
									
									
									
									$('div.featured_items_links').append("<a href='#web_" + var_name_replace + "' rel='gal' class='subitem_click " + first_click + "' title='" + $('docketCompany', xml).text() + ":" + $('docketCampaign', xml).text() + "'><img src='" + small_path + $(this).find('docketSubItempreview').text() + "' alt='" + $('docketCompany', xml).text() + " " + item_count + "' /></a>");
									$('div.featured_items_links').append("<div id='web_" + var_name_replace + "' class='web_link_hidden'><a href='" + $(this).find('docketSubItemfile').text() + "' title='click here to see website' target='_blank'><img src='" + lrg_path + $(this).find('docketSubItempreview').text() + "' alt='" + $('docketCampaign', xml).text() + "' /></a></div>");
									
									/*
									
									  //prep the comapny name for linkifacation 
                                         $var_name_trim = strtolower(trim($docket['Company_Name']));
                                          $var_name_replace = preg_replace('/( |\')/i',"_", $var_name_trim);
                                         
                                         echo "<a href='#wed_{$var_name_replace}' rel='gal' class='subitem_click {$var_isfirst}' title='{$docket['Company_Name']} : {$docket['Campaign']}'><img src='" . SMALL_PATH . $itemd['Img_thumb'] . "' alt='{$docket['Company_Name']} {$item_count}' /></a>";
                                         echo "<div id='wed_{$var_name_replace}' class='web_link_hidden'>
                                         
                                         <a href='{$itemd['file']}' title='click to see website' target='_blank'>
                                         <img src='" . LARGE_PATH . $itemd['file_preview'] . "' alt='{$docket['Company_Name']} Website' />
                                         </a>
                                         </div>";
									
									*/
									
								  break;
								
								  case "video":
								  
									
									
									//$('div.featured_items_links').append("<a href='" + $(this).attr('file')  + "' class='subitem_click' target='_blank'><img src='" + small_path + $(this).attr('thumb') + "' alt='" + $('docketCompany', xml).text() + " " + item_count + "' /></a>");
									$('div.featured_items_links').append("<a href='http://www.youtube.com/embed/" + $(this).find('docketSubItemfile').text() + "?rel=0' rel='gal' class='subitem_click " + first_click + "' target='_blank' title='" + $('docketCompany', xml).text() + ":" + $('docketCampaign', xml).text() + "'><img src='" + small_path + $(this).find('docketSubItempreview').text()  + "' alt='" + $('docketCompany', xml).text() + " " + item_count + "' /></a>");
								  
								  break;	
								  
								  
								  
								 }
										  
							  
							  
							});
						  
						  bindbehaviours('#content_column_wrapper');
					
					});

  
  
  
  
  
  return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Validate Email
//////////////////////////////////////////////////////////////////////////////////////////////////////
$('#contact_form').validate({
  
  submitHandler: function(form) {
                     
                    form.submit();
        },
 rules: {
    email: {
      required: true,
      email: true
    },
    fullname: 'required',
    message: 'required'
  }
});

 
 /*$('#reset').click(function(){
			
			$('#contact_us_frm').find('label.error').remove();
			$('#contact_us_frm input').text('');
			
			
});*/
	 
	 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////// Process functions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	 
	 $('a.process_click').click(function(e){
	  e.preventDefault;
	  
		$("#word_cloud_holder").find('img').attr('src', $(this).attr('href'));
		$("#word_cloud_holder").find('img').attr('alt', $(this).find('img').attr('alt'));
		
		link_temp = $(this).attr('href');
		
		$("li.nav_slide a").each(function(){
		  
		  
			if(link_temp != $(this).attr('href')){
			
			var findImgArray = $(this).find('img').attr('src').split('/'); //capture the image for processing
			var imgFilePath = '';
  
			for(var x = 0; x < findImgArray.length-1; x++){//rebuild the image path not including the image name
	
			imgFilePath = imgFilePath + findImgArray[x] + "/";
	
			}
  
			var imgSplitArray = findImgArray[findImgArray.length-1].split('_'); //capture the image for processing
			var imgName = imgSplitArray[0]; //capture the image for processing
  
			if(imgSplitArray.length == 3){
	
			var imgName = imgSplitArray[0] + '_' + imgSplitArray[1]; //capture the image for processing
	
			}
			else{
			var imgName = imgSplitArray[0]; //capture the image for processing
			}
  
  
			var hoverImgName = imgName + "_norm.gif";
  
			$(this).find('img').attr('src', imgFilePath + hoverImgName);

				  
			}
		  
		  });
		
		
	  
	  return false;
	  });
	 
	 
	 
	 
	 
///////////////////////////////////////////////////////////////////////
////clients click
/////////////////////////////////////////////////////////////////////
$('a.client_click').click(function(){
  
  var link_t = $(this).attr('href');
  
	$(link_t).trigger('click');
  
  
});


$('a.test_hidden_link').nyroModal({sizes: { minH: 600, minW: 300 } }); 





	 
	 });

