$(document).ready(function(){
	$('a').each(function(){
		$(this).bind('focus', function(){
			$(this).blur();})
	});
	
	$('.item.photographer .photographerDetails .title h2').each(function(i){
		var clickurl = $(this).find('a').attr('href');
		$(this).parent().parent().parent().bind('click',function() {
			/*window.location = ''+clickurl+'';*/
		});
			
	});		
	//console.log($(".imagebox").html());
  if($(".imagebox, a.fancybox").html() != null) {
    $(".imagebox, a.fancybox").fancybox();
  }
  
  $("a.fancybox_yt").click(function() {
    //var yt_this = $(this).attr('href');
    $.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
      'hideOnOverlayClick' : true,
      //'hideOnContentClick' : true,
			'title'			: this.title,
			'width'		: 680,
			'height'		: 495,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'		: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
    return false;
  });
	
	$(".tooltip").tooltip({showURL: false, delay: 0 });
	mytooltip('.ImageContainer','additionalInfo');
	clearInputFields();
	lensesTableHover();
        cameras_questionteaser_item();

	$('.glossars_rootItem').each(function(){
		 $(this).bind('click', function(){ElementDropdown(this);})
	});

  /** Photos **/
  $('.photos_item_thumb_previews').css({'opacity':'0.2'});
  $('.photos_item').hover(function() {
    $(this).find('.photos_item_thumb_previews').animate({'opacity':'1.0'});
  },
  function() {
    $(this).find('.photos_item_thumb_previews').animate({'opacity':'0.2'});
  });
});

function ElementDropdown(element){
 if ($(element).next().css("display") == "block"){
 	$(element).next().slideUp(100);
 } else {
 	$(element).next().slideDown(100);
 }
}


function clearInputFields() {
 $('input[type=text]:not(.no-auto-clear)').each(function(){
 var startText = $(this).val();
 $(this).bind('focus', function(){
 startText = $(this).val();
 $(this).val('');
 });
 });
}

function mytooltip(target_items, contentData){
$(target_items).each(function(i){
	var htmlData = $(this).parent().find("."+contentData).html();
 if(htmlData !=null) {	
	 $("body").append("<div class='"+contentData+"' id='"+contentData+i+"'>"+htmlData+"</div>");
	 var tooltip = $("#"+contentData+i);
	
	 $(this).hover(function(kmouse){
		 tooltip.css({left:kmouse.pageX+10, top:kmouse.pageY+5});
		 tooltip.show();
		  $(this).mousemove(function(kmouse){
			 tooltip.css({left:kmouse.pageX+10, top:kmouse.pageY+5});
			 tooltip.show();
		  });
	 },function(){
	 tooltip.hide();
	 });
 }
 });
}

var htmlcontainer = null;
var quantity = 1;
function rpc_single_camera(ajaxurl, htmlcontainer, quantity) {
  $.ajax({
    type: 'POST',
    dataType: 'html',
    cache: false,
    data: "limit="+quantity+"",
    url: ajaxurl,
    beforeSend: function() {
      $(htmlcontainer).fadeOut('slow');
      $(htmlcontainer).fadeIn('fast').html('<div class="ajax_loading">&nbsp;</div>');
    },
    success: function(htmlData) {
     $(htmlcontainer).fadeIn('slow').html(htmlData);
      window.setTimeout("rpc_single_camera('"+ajaxurl+"', '"+htmlcontainer+"', "+quantity+")",8000);
    },
    complete: function(){
    }
  });
}



function lensesTableHover() {
	$('.objektiveTable tbody tr').each(function(i) {
		$(this).hover(function () {			
	        $(this).css({'background':'#edf0e8'});
	      }, 
	      function () {	      	
	        $(this).css({'background':'none'});
	     }
	    );
	});
}

function cameras_questionteaser_item() {
	$('.cameras_questionteaser_item').each(function(i) {
		$(this).hover(function () {
	        $(this).addClass('cameras_questionteaser_item_active');
	      },
	      function () {
	        $(this).removeClass('cameras_questionteaser_item_active');
	     }
	    );
	});
}
