function tabOver(myElement) {
	var parent = jQuery(myElement).parent();
		parent = jQuery(parent).parent();
	    jQuery(parent).addClass('top_menu_link_container_o');
	 
}

function tabOut(myElement) {
	var parent = jQuery(myElement).parent();
		parent = jQuery(parent).parent();
	    if (submenuActive) {
	    	hidingMenu = window.setTimeout('jQuery("#" + "' + submenuActive + '").hide(); submenuActive = false', 500);
	    }
	    jQuery(parent).removeClass('top_menu_link_container_o');
}

function subTabOver(myElement) {
	var parent = jQuery(myElement).parent();
		parent = jQuery(parent).parent();
	    jQuery(parent).addClass('subnavi_o');
}

function subTabOut(myElement) {
	var parent = jQuery(myElement).parent();
		parent = jQuery(parent).parent();
	    jQuery(parent).removeClass('subnavi_o');
}

var submenuActive = false;
var hidingMenu = null;
function showSubmenu(menu, myElement) {
	window.clearTimeout(hidingMenu);
	hidingMenu = null;
	
	if (submenuActive && submenuActive != menu) {
		jQuery('#' + submenuActive).hide();
		submenuActive = false;
	}
	else if (submenuActive == menu) {
		return;
	}
	
	var pos = jQuery(myElement).parent().position();
	var y = pos.top;
	var x = pos.left;
	y += 33;
	x -= 17;
	jQuery("#" + menu).css("top", y + "px");
	jQuery("#" + menu).css("left", x + "px");
	jQuery("#" + menu).show();
	submenuActive = menu;
	jQuery("#" + menu).mouseenter(function() {
		window.clearTimeout(hidingMenu);
		hidingMenu = null;
	});
	jQuery("#" + menu).mouseleave(function() {
		hidingMenu = window.setTimeout('jQuery("#" + "' + menu + '").hide(); submenuActive = false', 500);
	});
}
function linkTabs() {
	jQuery('.contentbox-content-reiter').each(function(i){
		var bgImg = jQuery(this).css('background-image');
		if (bgImg != "" && bgImg != "none") {
			var pos = jQuery(this).position();
			var adjust = jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6 ? 0 : 70;
			var thisId = jQuery(this).attr('id').replace(/tab/, '');
			jQuery('#tabLink' + thisId).css("position", "absolute");
			jQuery('#tabLink' + thisId).css("top", pos.top - adjust + "px");
			jQuery('#tabLink' + thisId).css("left", pos.left + "px");
			jQuery('#tabLink' + thisId).css("height", "174px");
			jQuery('#tabLink' + thisId).css("width", "36px");
			jQuery('#tabLink' + thisId).show();
			
			if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6) {
				var bg = jQuery(this).css("background-image");
				jQuery(this).css("background-image", "");
				jQuery('#tabLink' + thisId).css("background-repeat", "no-repeat");
				jQuery('#tabLink' + thisId).css("overflow", "hidden");
				jQuery('#tabLink' + thisId).css("background-image", bg);
			}
			
		}
	});
}


var exposeTagformLoop = false;
function exposeTagform() {
	if (jQuery('#media_photo_tagform').is(':visible')) {
		var pos = parseInt(jQuery('#media_photo_tagform').css("left").replace(/px/, ""));
		//alert(pos);
		if (pos > 400) {
			jQuery('#media_photo_tagform').css("left", "400px");
		}
	}
	window.setTimeout("exposeTagform()", 300);
}
function makePopups() {
	jQuery('.popup').click(function(){
		var h = 600;
		var w = 680;
		var l = 0;
		var t = 0; 
		
		l = (screen.width)  ? (screen.width -  w) / 2 : 100;
		t = (screen.height) ?( screen.height - h) / 2 : 100;
		w = screen.width && screen.width < w ? screen.width : w;
		h = screen.height && screen.height < h ? screen.height : h;
		
		
		var href = jQuery(this).attr("href");
		var popup = window.open(href, '_blank', 'dependent=no,height=' + h + ",width=" + w + ",left=" + l + ",top=" + t + ",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
		if (!popup) {
			return true;
		}
		return false;
	});
}




function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.y)
      curtop += obj.y;
  return curtop;
}


function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1)
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}



var keyrow = Array(27,84,73,71,69,82);
var keystart = 0;
var keycheck = true;
jQuery(document).keyup(function(e) {
	if (e.keyCode!=keyrow[keystart]) keycheck = false;
	keystart++;
	if (keystart==keyrow.length && keycheck==true) recompile();
});

function recompile() {
	jQuery('img').each(function() {
		var dimension = (jQuery(this).width()>75) ? 150 : 75;
		var pos = jQuery(this).position();
		var left = (jQuery(this).width()-dimension)/2+pos.left;
		var top = (jQuery(this).height()-dimension)/2+pos.top;
		jQuery(this).css({'opacity':0.5});
		jQuery('body').append('<img src="/fileadmin/templates/img/tigergebruell.png" style="position:absolute; z-index:1000; width:'+dimension+'px; left:'+left+'px; top:'+top+'px;" />');
	});
}