Cufon.replace('#navigation a', {
	hover: true
});
Cufon.replace('#landing a', {
	hover: true
});
Cufon.replace('.block_adwords a', {
  hover: true
});
Cufon.replace('.media_text, h1, h2, h3, h4, h5, h6, span.titleh1, #fancybox-wrap .columnlist');

$(document).ready(function() {
	$('.hide').hide();
	$('#mediabar').cycle({
		fx: 'fade'
	});
	
	if($("a.fancybox").length > 0) {
		$("a.fancybox").fancybox({
			'titleShow'	: false	
		});
	}
	if($(".youtubeblock").length > 0) {
		$(".youtubeblock .youtube").each( function() {
		  var CurrentUrl   = $(this).attr("href");
		  var YouTubeImage = GetYouTubeScreen(CurrentUrl);
		  $(this).html("<img style=\"width: 210px;\" src=\"" + YouTubeImage + "\" alt=\"youtube\" />"); 
		});
	  }
	  
	$(".youtubeblock .overlay").click(function() { $('.youtube', $(this).parent()).trigger('click'); });                             
	  $(".youtube").click(function() {
		  $.fancybox({
				  'padding'				: 0,
				  'autoScale'			: false,
				  'transitionIn'		: 'none',
				  'transitionOut'		: 'none',
				  'titleShow'	 		: false,
				  'title'				: this.title,
				  'width'				: 854,
				  'height'				: 480,
				  'href'				: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + "&autoplay=1&egm=0&rel=0",
				  'type'				: 'swf',
				  'swf'					: {
					'wmode'						: 'transparent',
					  'allowfullscreen'	: 'true'
				  }
			  });
  
		  return false;
	  });
  
	  $("a[href^='http://www.youtube.com/watch?v=']").click(function(){
		  $.fancybox({
				  'padding'				: 0,
				  'autoScale'			: false,
				  'transitionIn'	: 'none',
				  'transitionOut'	: 'none',
				  'titleShow'	 		: false,
				  'title'					: this.title,
				  'width'					: 854,
				  'height'				: 480,
				  'href'					: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + "&autoplay=1",
				  'type'					: 'swf',
				  'swf'						: {
					'wmode'						: 'transparent',
					  'allowfullscreen'	: 'true'
				  }
			  });
  
		  return false;
	  });

	  $('a[rel=external]').attr('target','_blank');	
	  
	  $(".list-toggle .item").each(function() {
		$(this).find(".category_name").click(function() {      
		  // set settings for current item
		  $(this).css("background-image", "url(/pics/bg_list-toggle-item_open.png)");
		  $(this).addClass("current");
		  
		  $(this).next("div:first").stop(true,true).slideToggle(function() {
			if($(this).css("display") == "none") {
			  $(this).prev(".category_name").css("background", "url(/pics/bg_list-toggle-item_closed.png) 0px 15px no-repeat");  
			  $(this).prev(".category_name").removeClass("current");
			} else {
			  $(this).prev(".category_name").css("background", "url(/pics/bg_list-toggle-item_open.png) 0px 15px no-repeat");
			  $(this).prev(".category_name").addClass("current");  
			}
		  });
	
		});
	  });    
	  
	  if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
		   if($(".dropdown").length > 0) {
				$(".dropdown").each(function() {
				  var _this = $(this);
				  var Dropdown_TimeOut = null;
				  $(_this.parent()).unbind('hover');
				  $(_this.parent()).click(function() {
					  clearTimeout(Dropdown_TimeOut);  
					  _this.next(".dropdown_content").show();
					  _this.addClass("selected");  
					}, function() {
					  Dropdown_TimeOut = setTimeout(function() {
						_this.next(".dropdown_content").hide(); 
						_this.removeClass("selected");   
					  }, 50);
					   
					}
				  );
				}); 
			  }
	  } else {
		   if($(".dropdown").length > 0) {
				$(".dropdown").each(function() {
				  var _this = $(this);
				  var Dropdown_TimeOut = null;
				  $(_this.parent()).unbind('hover');
				  $(_this.parent()).hover(function() {
					  clearTimeout(Dropdown_TimeOut);  
					  _this.next(".dropdown_content").show();
					  _this.addClass("selected");  
					}, function() {
					  Dropdown_TimeOut = setTimeout(function() {
						_this.next(".dropdown_content").hide(); 
						_this.removeClass("selected");   
					  }, 50);
					   
					}
				  );
				}); 
			  }
		}

});

function GetYouTubeScreen(Url) {
  if(Url === null){ 
    return ""; 
  }
  
  var VideoId;
  var Results;

  Results = Url.match("[\\?&]v=([^&#]*)");
  VideoId = ( Results === null ) ? Url : Results[1];
  
  return "http://img.youtube.com/vi/"+VideoId+"/0.jpg";
}
