Cufon.replace('.main_nav a',{hover: true}); 
Cufon.replace('.top_nav a',{hover: true});
Cufon.replace('.footer p');
Cufon.replace('.footer a',{hover: true});
Cufon.replace('.search_pop h2',{hover: true});
Cufon.replace('.more_plus a',{hover: true});


function clickedplayfromflash(Txt) {
	
	moveVideoPlace(Txt);
	setTimeout("stopvideoflash("+Txt+")",1000);
}

function moveVideoPlace(numvid) {
	var element = $('.scroll-pane');
	var jScrollPaneAPI = element.data('jsp');
	if (navigator.appName.indexOf("Microsoft") != -1) {
		var pos = $('#ieflashfallback'+numvid).parent().parent().offset();
	}
	else
	{
		var pos = $('#flashfallback'+numvid).parent().parent().offset();
	}
	
	jScrollPaneAPI.scrollByX(pos.left - 165, true);
	
}

function stopvideoflash(numvid)
{
	var i=0;
	var m=jQuery(".video_box").length;
	for (i=0;i<m;i++) {
		var myflashid = document.getElementById('ieflashfallback'+i);
		if(myflashid) {
			if (navigator.appName.indexOf("Microsoft") != -1) {
				if(i !=numvid)
				{
					try{document.getElementById('ieflashfallback'+i).callflash('stopvideo');} catch(err){};
				}
						
			} else {
				if(i !=numvid)
				{
					document.getElementById('flashfallback'+i).callflash('stopvideo');
				}
			}
		}
	}
}

jQuery(function()
	{
		
		jQuery(".content-body").css("overflow","hidden");
		
		/*
		//about us popup
		jQuery(".about").click(function() {
		  jQuery(".contact_pop").fadeOut("fast");
		  jQuery(".clients_pop").fadeOut("fast");
		  jQuery(".about_pop").fadeIn("fast");
		});
		
		jQuery(".close_about").click(function() {
		  jQuery(this).parent("div").fadeOut("fast");
		});
		
		//clients popup
		jQuery(".clients").click(function() {
		  jQuery(".contact_pop").fadeOut("fast");
		  jQuery(".clients_pop").fadeIn("fast");
		  jQuery(".about_pop").fadeOut("fast");
		});
		
		jQuery(".close_clients").click(function() {
		  jQuery(this).parent("div").fadeOut("fast");
		});
		
		//contact popup
		jQuery(".contact").click(function() {
		  jQuery(".contact_pop").fadeIn("fast");
		  jQuery(".clients_pop").fadeOut("fast");
		  jQuery(".about_pop").fadeOut("fast");
		});
		*/
		
		
		jQuery(".close_contact").click(function() {
		  jQuery(this).parent("div").fadeOut("fast");
		});
		
		//Search Field
		var clearMePrevious = 'SEARCH HERE';
		
		// clear input on focus
		$(".search_pop input").focus(function()
			{
				if($(this).val()==$(this).attr('value'))
			{
				clearMePrevious = $(this).val();
				$(this).val('');
			}
		});
		
		// if field is empty afterward, add text again
		$(".search_pop input").blur(function()
			{
				if($(this).val()=='')
			{
				$(this).val(clearMePrevious);
			}
		});
		
		//search popup
		jQuery(".search").click(function() {
		  jQuery(".search_pop").fadeIn("fast");
		  jQuery(".follow_pop").fadeOut("fast");
		});
		
		jQuery(".search_close").click(function() {
		  jQuery(".search_pop").fadeOut("fast");
		});
		
		//follow popup
		jQuery("#follow").click(function() {
		  jQuery(".follow_pop").fadeIn("fast");
		});
		
		//work popup
	
		jQuery(".more_plus").click(function() {
		  jQuery(this).siblings("div.campaign_preview").fadeIn("fast");
		  jQuery(".contact_pop").fadeOut("fast");
		  jQuery(".clients_pop").fadeOut("fast");
		  jQuery(".about_pop").fadeOut("fast");
		});
	
		$('.close_info').live('click', function() {
		  jQuery(this).parent("div.campaign_info").animate({
			opacity: "hide"
		  }, 800);
		});
		
		jQuery(".close").click(function() {
		  jQuery(this).parent("div").fadeOut("fast");
		});
		
		jQuery(".plus").hover(function() {
		  jQuery(".plus .more").fadeToggle("fast");
		});
		
		jQuery(".div_scroll").focus();
		
		jQuery(".more_info").click(function() {
		  jQuery(this).parent("div.intro").siblings("div.campaign_info").css("position", "absolute");
		  jQuery(this).parent("div.intro").siblings("div.campaign_info").css("left", "475px");								
		  jQuery(this).parent("div.intro").siblings("div.campaign_info").animate({
			opacity: "show"
		  }, 1000);
		});
		
		//Primary Nav Link Exchange
		//jQuery('.main_nav a.about').attr("href","javascript://");
		//jQuery('.main_nav a.clients').attr("href","javascript://");
		//jQuery('.main_nav a.contact').attr("href","javascript://");
		jQuery('.top_nav a.search').attr("href","javascript://");
		
		jQuery('.content-cols').columnize({
			   width : 400,
			   height : 360,
			   doneFunc : function(){
				   //jQuery('.last').empty().remove();
				   var newWidth;
				   newWidth = (jQuery('.column').length * 430);
				   jQuery('.content-cols').width(newWidth);
			   }
	    });
		
		jQuery('.campaign_info').columnize({
			   width : 400,
			   height : 400,
			   doneFunc : function(){
				   jQuery('.last').empty().remove();
				   var newWidth;
				   newWidth = (jQuery('.column').length * 430) - 410;
				   jQuery('.campaign_info').width(newWidth);
				   jQuery('.campaign_info').hide();
				   jQuery('.campaign_info').append('<span class="close_info">CLOSE</span>');
			   }
	    });
		
		var widthContentBodyTop = 0;
		var widthContentBodyBottom = 0;
		jQuery('.div_top_scroll').children("div.content-body").each(function() {
			widthContentBodyTop += jQuery(this).outerWidth( true );
		});
		jQuery('.div_bottom_scroll').children("div.content-body").each(function() {
			widthContentBodyBottom += jQuery(this).outerWidth( true );
		});

		jQuery('.div_top_scroll').css('width', widthContentBodyTop);
		jQuery('.div_bottom_scroll').css('width', widthContentBodyBottom);
		
		var widthContentBody = 0;		
		jQuery('.div_scroll').children("div.content-body").each(function() {
			widthContentBody += jQuery(this).outerWidth( true );
			if(jQuery('.campaign_info').length > 0) {
				widthContentBody = widthContentBody + jQuery('.campaign_info').width() - 880;
			}
		});
		
		if(jQuery('body').hasClass('work_page')) {
			//widthContentBody = widthContentBody + 725;
		}
		
		jQuery('.div_scroll').css('width', widthContentBody);
		
		/*** sniff the UA of the client and disable the jScrollPane ***/
		var ua = navigator.userAgent;
		var checker = {
			iphone: ua.match(/(iPhone|iPod)/),
			ipad: ua.match(/(iPad)/),
			blackberry: ua.match(/BlackBerry/),
			android: ua.match(/Android/)
		};

		if (checker.android){
			//Do nothing
			jQuery('div.header').css('position','absolute');
			jQuery('html').css('background-color','#FFF');
		}
		else if (checker.iphone){
			//Do nothing
			jQuery('div.header').css('position','fixed');
			jQuery('html').css('background-color','#FFF');
		}
		else if (checker.ipad){
			var contentH = jQuery('.content-blog').outerHeight( true );
			jQuery('.single_post_content .image_box').css("height",contentH);
			jQuery('video').bind(
					'play',
					function(e) {
						e.preventDefault();
						
						var pos = $(this).offset();
						scrollNav.scrollTo( (pos.left-165),0, 1000, true);
					}
			);
			
			try
			{
			var scrollNav;
			scrollNav = new iScroll('iwrapper');
			}
			catch(err)
			{
			// do nothing because iwrapper doesn't exist on this page
			}
			
			try
			{
			var scrollNav2;
			scrollNav2 = new iScroll('iwrapper2');
			}
			catch(err)
			{
			// do nothing because iwrapper doesn't exist on this page
			}
			

		}
		else if (checker.blackberry){
			//Do nothing
			jQuery('div.header').css('position','absolute');
			jQuery('html').css('background-color','#FFF');
		}
		else {
			
			(function(jQuery){
				
				jQuery('html').css("background-color","#ffffff");
				var contentH = jQuery('.content-blog').outerHeight( true );
				jQuery('.single_post_content .image_box').css("height",contentH);
				
				var element = jQuery('.scroll-pane');
				
				element.jScrollPane({
					enableKeyboardNavigation: false,
					animateScroll: true,
					animateDuration: 800,
					hideFocus: true,
					animateTo: true,
					scrollByX: 711
				});
				var jScrollPaneAPI = element.data('jsp');
				
				jQuery('.scroll-to-click').bind(
					'click',
					function(e) {
						e.preventDefault();
						
						jScrollPaneAPI.positionDragX(50, false);
						jScrollPaneAPI.positionDragX(100, true);
					}
				);
				
				jQuery('video').bind(
					'play',
					function(e) {
						e.preventDefault();
						var elm = e.target;

						//jScrollPaneAPI.scrollToElement($(this).parent(), true, true);
						
						var pos = $(this).parent().offset();
						var playbtn = $(this).parent().attr("id");
						jScrollPaneAPI.scrollByX(pos.left - 165, true);
						var i=0;
						var l=jQuery('.video_box').length;
						for (i=0;i<l;i++) {
							if( playbtn != i) {
								jQuery('video')[i].pause();	
							}
						}
					}
				);
				
				var throttleTimeout;
				$(window).bind(
					'resize',
					function()
					{
						if ($.browser.msie) {
							// IE fires multiple resize events while you are dragging the browser window which
							// causes it to crash if you try to update the scrollpane on every one. So we need
							// to throttle it to fire a maximum of once every 50 milliseconds...
							if (!throttleTimeout) {
								throttleTimeout = setTimeout(
									function()
									{
										jScrollPaneAPI.reinitialise();
										throttleTimeout = null;
									},
									50
								);
							}
						} else {
							jScrollPaneAPI.reinitialise();
						}
					}
				);
				
				jQuery(document).ready(function(){
					jQuery('.scroll-to-click').trigger('click');
				});
				
			}(jQuery));
			
		}
		
		jQuery('.wpcf7-submit').addClass('submit');
		
		if (navigator.appName.indexOf("Microsoft") != -1) {
		}
		else
		{
			// Add VideoJS to all video tags on the page when the DOM is ready
			VideoJS.setupAllWhenReady();
		}
		
		jQuery(".twit-text").each(function(index) {
			jQuery(this).attr("id", index);
			jQuery("#twitter-feed"+index).append(jQuery(this).html());
		});
	}
);
