var $j = jQuery.noConflict();

$j(document).ready(function(){


	/* ###################################################################################### */
	/* Login in fancybox */
	/* ###################################################################################### */
	
	$j("a[href*='index.php?id=1122']").fancybox({
		'autoDimensions' : 'true',
		'overlayOpacity' : 0.5,
		'enableEscapeButton' : 'true',
		'showCloseButton' : 'true',
		'speedIn' : 800,
		'speedOut' : 300,
		'centerOnScroll' : 'true',
		'type' : 'ajax',
		'titleShow': 'false',
		'href' : 'index.php?id=1122',
		'hideOnOverlayClick' : 'false'
	}).resize();
	$j("a[href*='index.php?id=1185']").fancybox({
		'autoDimensions' : 'true',
		'overlayOpacity' : 0.5,
		'enableEscapeButton' : 'true',
		'showCloseButton' : 'true',
		'speedIn' : 800,
		'speedOut' : 300,
		'centerOnScroll' : 'true',
		'type' : 'ajax',
		'titleShow': 'false',
		'href' : 'index.php?id=1185'
	}).resize();
	
	//var timestamp = new Date().getTime();
	
	//$j("a[href*='index.php?id=1122']").attr("href","index.php?id=1122&"+timestamp);
	
	$j("a[href*='index.php?id=1185']").live('click', function() {
		$j.fancybox.showActivity();
		$j.ajax({
			url: $j(this).attr('href'),
			success: function(data) {
				$j.fancybox($j(data));
				/* console.log($j(data).find(".tx-felogin-pi1")); */
				 //if (window.location.href.indexOf("id=1121") != -1) {
				 if ($j("div.quickjumpextended h4").html().indexOf("Abmelden") != -1) {
    					//console.log("kjhkjh");
    					$j("#fancybox-content p.bodytext").html("Oder <a class='internal-link' target='_self' title='Opens internal link in current window' href='index.php?id=1184&no_cache=1'>klicken Sie hier</a>, um zum Download-Bereich zurückzugelangen.");

    				}
			}
		});
		return false;
	});
	
	
	
	$j("#loginForm input[type='submit']").live('click', function() {
		$j.fancybox.showActivity();
		var form = $j('#loginForm');
		//alert(form.attr('action'));
		$j.ajax({
			url: form.attr('action'),
			//url: "1121.0.html",
			data: form.serialize(),
			success: function(data, textStatus, XMLHttpRequest) {
				//$console.log(data);
				var temp = data.substr(0, 10)
				/* console.log(temp); */
				if (temp=='<!DOCTYPE ') { 
					window.location.reload(); 
				}
				else { 
					$j.fancybox(data); 
				}
			}
		});
	return false;
	}); 
	
	$j("#fancybox-close, #fancybox-overlay").live('click', function() {
		window.location.reload(); 
	});
	
 	/* make download items the same height */
	var downloadItems = $j(".downloadItem");
	//console.log(downloadItems);
	var maxHeight = 0;
    	downloadItems.each(function() {       
          if($j(this).height() > maxHeight) {
            maxHeight = $j(this).height();;
          }
        });
        downloadItems.height(maxHeight);
	

});
