function newFreeCap(id, noImageMessage) {
	if (document.getElementById) {
			// extract image name from image source (i.e. cut off ?randomness)
		var theImage = document.getElementById("tx_srfreecap_pi2_captcha_image_"+id);
		var parts = theImage.src.split("&");
			// add ?(random) to prevent browser/isp caching
			// parts[0] should be base url up to eID parameter
			// parts[1] should be id=page_id
			// parts[2] should be L=sys_language_uid
		var LParameterInUse = (typeof(parts[2]) != "undefined") && (parts[2].indexOf("L=") != -1);
		theImage.src = parts[0] + "&" + parts[1] + (LParameterInUse ? "&" + parts[2] : "") + "&set=" + Math.round(Math.random()*100000);
	} else {
		alert(noImageMessage ? noImageMessage : "Sorry, we cannot autoreload a new image. Submit the form and a new image will be loaded.");
	}
}

$.fn.setHeight = function() { 	
	var main_padding_top 	= $('#main_content').css('padding-top');
	var main_padding_bottom = $('#main_content').css('padding-bottom');
	var main_margin_top 	= $('#main_content').css('margin-top');
	var left_margin_bottom 	= $('#left').css('margin-bottom');
	var flex_offset_top		= $('#flex_content').offset().top;
	var empty_offset_top		= $('.empty').offset().top;
	
	var navi_outerHeight 	= $('#navi').outerHeight();
	var tlayer_outerHeight 	= $('#tlayernav').outerHeight();	
	var right_outerHeight 	= $('#right').outerHeight();	
	var right_cropped 		= right_outerHeight - tlayer_outerHeight - parseInt(main_margin_top);
	var left_outerHeight 	= $('#left').outerHeight();
	var main_content_outerHeight 	= $('#main_content').outerHeight();	
	
	//set pseudo content to avoid function error
	$("#main_content").append("<div class='dummy'></div>");

	var last_element_top = $('#main_content > :last').position().top;	
	var last_element_height = $('#main_content > :last').outerHeight();	
	var main_content_height_content = last_element_top + last_element_height + 11;		
	var flex_content_outerHeight 	= $('#flex_content').innerHeight();
	var flex_content_wo_empty		= flex_content_outerHeight - $('.empty').outerHeight() ;//- 7;
	
	if(main_content_height_content >= main_content_outerHeight){
		var main_content_height = main_content_height_content;
	}else{
		var main_content_height = main_content_outerHeight;
	}		
	if($('#flex_content :last-child').is('.empty')){
		
	}else{
		//$('#flex_content').append("<div class='empty'></div>");
	}
		 
	if(right_outerHeight >= left_outerHeight || (right_cropped > main_content_height_content &&  main_content_height_content > flex_content_wo_empty) || (right_cropped > flex_content_wo_empty && right_cropped > main_content_height_content)){
		if(right_cropped > main_content_height_content){			
			$('#main_content').css("height",right_cropped - parseInt(main_padding_top) - parseInt(main_padding_bottom));
			main_content_outerHeight 	= $('#main_content').outerHeight();
		}else{			
			$('#main_content').css("height",main_content_height_content);
			main_content_outerHeight 	= $('#main_content').outerHeight();
		}
		$('.empty').height(main_content_outerHeight - flex_content_wo_empty);		
	}else{			
		if(flex_content_wo_empty > main_content_height){						
			$('.empty').remove();
			//$('.top-breaker').remove();
			$('#flex_content > :last').find(".top-breaker").remove();
			$('#flex_content > :last').css("margin-bottom",0);
			flex_content_wo_empty = $("#flex_content").outerHeight();			
			$('#main_content').height(flex_content_wo_empty - parseInt(main_padding_top) - parseInt(main_padding_bottom));		
		}else{			
			//alert("flex_wo_empty <= als main_content_outerHeight");
			if((main_content_height_content + parseInt(main_padding_top) + parseInt(main_padding_bottom))  >= (flex_content_wo_empty + 30)){				
				$('.empty').hide().height(0);
				$('.empty').show();				
				$('#main_content').css("height",main_content_height_content);
				main_content_outerHeight 	= $('#main_content').outerHeight();			
				$('.empty').height(main_content_outerHeight - flex_content_wo_empty);				
			}else{				
				$('#main_content').css("height",main_content_height_content) ;
				main_content_outerHeight 	= $('#main_content').outerHeight();	
				$('.empty').hide().height(0);
			}						
		}
	}
	
	$('.empty').corner("6px");
	$(".dummy").remove();
	return false; 
}

$.extend({
  /* ----- get URL Paramter ----- */
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&amp;');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  /* ----- get URL Paramter ----- */
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }, 
  /* ----- set Price ----- */
  setPrice: function(){
  	var c = 0;
  	var pageID = parseInt($.getUrlVar('id'));
  	var slideSpeed = 1500;
  	if (pageID == 1067) {
  		var adType = "BASIS";
  	}
  	if (pageID == 1066) {
  		var adType = "PREMIUM";
  	}  	
  	var choosed_packet = $('.tx-exinitjobexchange-pi1-rabatt_packet').val();
	//nur für vorschau erforderlich / zur zeit nicht aktiv
	/*if($('.tx-exinitjobexchange-pi1-rabatt_packet').length <= 0){
		var choosed_packet = $('.rabatt_packet').text().toUpperCase();
	}*/
  	if (adType == "BASIS") {
  		switch (choosed_packet) {
  			case "KOMBI":
  				var price_total = "60";
  				break;
			case "NORDEN":
  				var price_total = "40";
  				break;
  			case "KÖLN+DÜSSELDORF":
  				var price_total = "72";
  				break;
  			case "RHEIN-MAIN":
  				var price_total = "72";
  				break;
  			case "MITTLERER WESTEN":
  				var price_total = "150";
  				break;
  			case "TECHNIK":
  				var price_total = "102";
  				break;
  			case "WIRTSCHAFT":
  				var price_total = "168";
  				break;				
  		}
  	}
  	else {
  		switch (choosed_packet) {
  			case "KOMBI":
  				var price_total = "110";
  				break;
			case "NORDEN":
  				var price_total = "90";
  				break;
  			case "KÖLN+DÜSSELDORF":
  				var price_total = "162";
  				break;
  			case "RHEIN-MAIN":
  				var price_total = "162";
  				break;
  			case "MITTLERER WESTEN":
  				var price_total = "336";
  				break;
  			case "TECHNIK":
  				var price_total = "229";
  				break;
  			case "WIRTSCHAFT":
  				var price_total = "378";
  				break;
  		}
  	}  	
  	price_total = "Preis insgesamt <b>" + price_total + " &euro;</b> zzgl. Mwst.";
  	if($(".tinyprice").length == 0){
		$(".tx-exinitjobexchange-pi1-rabatt_packet").after("<span class='tinyprice'>"+price_total+"</span>");
	}else{
		$(".tinyprice").remove();
		$(".tx-exinitjobexchange-pi1-rabatt_packet").after("<span class='tinyprice'>"+price_total+"</span>");
	}
  	if($('.tx-felogin-pi1').length == 0 && $('.job_preview_table').length == 0 && $('.tx-exinitjobexchange-pi1-rabatt_packet').length > 0){
		if ($('.priceparser').length == 0) {
	  		$('.empty').before("<div style='display:none;' class='ce priceparser'><h3 class='ui-mel-flex-left-header'>Preisberechnung</h3><p>Sie haben für Ihre Anzeige das Rabatt Paket <b>" + choosed_packet + "</b> ausgewählt! </p><p>" + price_total + " </p></div>");
	  		$('.priceparser').slideDown(slideSpeed);
	  	}
	  	else {
	  		$('.priceparser').remove();
	  		$('.empty').before("<div class='ce priceparser'><h3 class='ui-mel-flex-left-header'>Preisberechnung</h3><p>Sie haben für Ihre Anzeige das Rabatt Paket <b>" + choosed_packet + "</b> ausgewählt! </p><p>" + price_total + " </p></div>");
	  	}
	  	setTimeout(function(){
	  		$('#left').setHeight();
	  	}, slideSpeed);
  	}
  },
  /* ----- decode URL ----- */
  decodeString: function(psEncodeString){
	  return unescape(psEncodeString); 
  }
});
$.fn.fadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};




$(document).ready(function(){		
	$('#bookmarking').hover( function(){
		$(this).css({cursor:'pointer'});
	});
	$('#bookmarking').click( function(e) { 
		if($('#bookmarks').css('display') == 'none'){
			$('#bookmarks').slideToggle().offset({ top: e.pageY, left: e.pageX });
		}else{
			$('#bookmarks').slideToggle();
		}		
	});	
	
	$('#tellfriend').parent().corner();
	
	if($.browser.msie){
		$('.container_top').corner("top 6px");
		$('#services, #tellfriend, .ang_table_header').corner("6px");	
	}else{
		$('.tx-felogin-pi1 h3, #flex_content div h3, .container_top,#right h3').corner("top 6px");
		$('#services, .ang_table_header, #flex_content .top div, #flex_content div .ce, #right div').corner("6px");	
		$('#tlayernav').corner("tr,br,bl 4px");
	}
	$('#bookmarking').corner("bottom 6px");
	

	if($('.sendAFriendLinkPopup').length > 0){
		var url = $(".sendAFriendLink").attr("href");
		$(".sendAFriendLink").remove();
		//$(".sendAFriendLinkPopup").hide('fast');	
		$(".sendAFriendLinkPopup").removeAttr("href");
		$(".sendAFriendLinkPopup").removeAttr("onclick");
		$(".sendAFriendLinkPopup").removeAttr("onkeypress");
		$(".sendAFriendLinkPopup").removeClass("sendAFriendLinkPopup").addClass("sendAFriendLink");
		
		//$(".sendAFriendLink").removeAttr("href");
		//$(".sendAFriendLink").removeAttr("onclick");
		//$(".sendAFriendLink").removeAttr("onkeypress");
		url = url.split('?tipUrl=');
		var ajaxPath = url[0];
		var ajaxParam = $.decodeString(url[1]);
		//$("#sendAFriendLink").show();
		
		$(".sendAFriendLink, input[type=button]").hover(
			function () {			    
			    $(this).css({cursor:'pointer'});
			} 
		);
		$(".sendAFriendLink ").text('');
		
		//$('#services').after('<input class="ajaxUrl" type="hidden" name="ajaxUrl" >');		
		//$('.ajaxUrl').text(ajaxPath);
		//$('#bookmarking').after('<p>Test</p>');
		
		/*$('*').hover(function(){
			$('#console_log').text("z-index: " + $(this).css('z-index') + " und get : " + $(this).selector);
			
		});*/
		
		$(".sendAFriendLink").click(function(){		
			$.ajax({					
				url:ajaxPath,
				type: "GET",					
				data: {tipUrl:ajaxParam},
				dateType: 'html',
				beforeSend: function() {
					$('#services').after('<input type="hidden" name="ajaxUrl" value="'+ ajaxPath + '">');					
					/*$('#icons').append('<div id="overlay" ></div>');*/
					/*$('#overlay').css({width:'10000px', height:'10000px', 'z-index':'888', left:'-1000px',top:'-1000px', position:'absolute',backgroundColor: 'black',opacity:'0.7'});*/
					if($.browser.msie){
						
						$('#overlay').css( {opacity:0.7,backgroundColor:'black'});
						$('#overlay').fadeIn(3000);
							/*css({width:'10000px', height:'10000px', 'z-index':'888', left:'-1000px',top:'-1000px', position:'absolute',opacity:0})*/
							
						
					}else{
						$('#overlay').toggle();
						$('#overlay').animate( {opacity:0.7,backgroundColor:'black'}, 3000 );
						/*$('#overlay').css({width:'10000px', height:'10000px', 'z-index':'888', left:'-1000px',top:'-1000px', position:'absolute',backgroundColor: 'black',opacity:'0.7'});*/
					}
				},
				// Es hat funktioniert?
				success: function(data) {				
						$("#tipForm").html(data);	
						
						if($.browser.msie){
							$("#tellfriend").fadeToggle('slow');								
						}else{
							$("#tellfriend").fadeToggle('slow').corner("6px");								
						}
						$('input#close').click(function() {
					    	$("#tellfriend").fadeToggle('slow');	
					    	$("input[name=ajaxUrl]").remove();
					    	$("#overlay").animate( {opacity:0,backgroundColor:'black'}, 1000 );
					    	setTimeout(function(){    	
								$('#overlay').toggle();	
						        },1000);	
					    });
						$(".sendAFriendLink, input[type=button]").hover(
								  function () {			    
								    $(this).css({cursor:'pointer'});
								  } 
						);							
				},
				// Schade, es war ein Fehler
				error: function(error) {
					alert("Sorry, hat nicht funktioniert");
				}
			});		
		});	
	} 
	

	
	
	
	
	var choosed_packet = $('.tx-exinitjobexchange-pi1-rabatt_packet').val();
	if(choosed_packet == "KOMBI"){
			$('table.portal_choose').show();
	}else{
		$(".tx-exinitjobexchange-pi1-portal").attr("checked", false); 
	}
	
	$('.stw-k-toggle,.stw-mz-toggle,.stw-do-toggle,.stw-da-toggle,.stw-due-toggle,.stw-kl-toggle').hide();	
		
	if($('.empty').length > 0){
	
	}else{
		$('#flex_content').append("<div class='empty'></div>");		
	}
		
	
	$('#left').setHeight();
	
	if (parseInt($.getUrlVar('id'))==1067 || parseInt($.getUrlVar('id'))==1066 ) {
		$.setPrice();
	}
	$('.job_detail_table .ang_table_header').click(function(){
	  	if($(this).find("img").attr("src") == "fileadmin/templates_stellenwerk/img/minus.gif"){
			 var img_src = "fileadmin/templates_stellenwerk/img/plus.gif";
		}else {
			var img_src = "fileadmin/templates_stellenwerk/img/minus.gif";
		}	  		 
	  	$(this).parent().parent().find('.ang_table_zeile_1, .ang_table_zeile_2').parent().toggle();		
	  	$(this).find("img").attr({ 
         		src: img_src,
          		title: "open/close",
          		alt: "open/close"
        });	
		$('#left').setHeight();	
	});
    
	

	$('.portal-choose input[type=checkbox]').click(function(){		
		var c = 0;
		var pageID = parseInt($.getUrlVar('id'));
		var slideSpeed = 1500;
		if(pageID == 1067){
			var price = 40;		
		}
		if(pageID == 1066){
			var price = 90;		
		}
		//$('.portal-choose input').is(':checked').each(function(){		
		$(".portal-choose input[type=checkbox]:checked").each(function() {		  
			  	c = c + 1;			 	 
			}		
		);	
		
		if(c == 1){
			var portals = "Portal";
		}else{
			var portals = "Portale";
		}
		var price_total = c * price;
		price_total = "Preis insgesamt <b>" + price_total + " &euro;</b> zzgl. Mwst.";
		runtime_info = "Beachten Sie bitte, dass die Laufzeiten der Portale unterschiedlich sind!";
		if($(".tinyprice").length == 0){
			$(".portal-choose label:last").after("<div class='tinyprice'>"+price_total+" <br/>"+runtime_info+"</div>");
		}else{
			$(".tinyprice").remove();
			$(".portal-choose label:last").after("<div class='tinyprice'>"+price_total+" <br/>"+runtime_info+"</div>");
		}
		
		if($('.priceparser').length == 0){			
			$('.empty').before("<div style='display:none;' class='ce ui-corner-all priceparser'><h3 class='ui-mel-flex-left-header ui-corner-tr ui-corner-tl'>Preisberechnung</h3><p>Sie haben für Ihre Anzeige " + c + " " + portals +  " ausgewählt! </p><p>" + price_total + " </p></div>");
			$('.priceparser').slideDown(slideSpeed);			
		}else{
			$('.priceparser').remove();
			$('.empty').before("<div class='ce ui-corner-all priceparser'><h3 class='ui-mel-flex-left-header ui-corner-tr ui-corner-tl'>Preisberechnung</h3><p>Sie haben für Ihre Anzeige " + c + " " + portals +  " ausgewählt! </p><p>" + price_total + " </p></div>");
		}
		setTimeout(function(){    	
			$('#left').setHeight();	
	        },slideSpeed
	    );	
	});
	
	$('.tx-exinitjobexchange-pi1-rabatt_packet').change(function(){		
		choosed_packet = $('.tx-exinitjobexchange-pi1-rabatt_packet').val();
		if(choosed_packet == "KOMBI"){
			$('table.portal_choose').fadeIn(1000);
			$(".tx-exinitjobexchange-pi1-portal").eq(0).attr("checked", true); 
		}else{
			$('table.portal_choose').fadeOut(1000);
			$(".tx-exinitjobexchange-pi1-portal").attr("checked", false); 
		}		
		$.setPrice();
		
	});

/*$('#main_content, .ce, #footer, .empty').addClass('ui-corner-all');	
$('.counter_all, .counter_24, .usercounter_box')	   .addClass('ui-corner-br ui-corner-tr ');
$('.icon_all, .icon_24, .icon_usercounter')	   .addClass('ui-corner-bl ui-corner-tl ');*/
$('#flex_content .ce h3').addClass('ui-mel-flex-left-header').css('font-weight','bold');
$('#right .ce h3').addClass('ui-mel-flex-right-header').css('font-weight','bold');
$('#tlayernav').addClass('ui-mel-nav2-header ');	

$('.main-content-box-round-with-border,.main-content-hint-box,.main-content-error-box,.main-content-hint-box,.main-content-attention-box').addClass('ui-corner-all');

$('a.intern_img').text(" ").append("<img src='fileadmin/templates_stellenwerk/img/button-klein.png'></img> ");
	
$('.poi').click(function(){	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$('.poi').css('background-color','#F4CA44');
	}		
});

$('.poi-hamburg').click(function(){
	$('.stw-hh-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#ED8200');
	}
	$('.stw-mz-toggle,.stw-k-toggle,.stw-due-toggle,.stw-do-toggle,.stw-da-toggle,.stw-kl-toggle').hide();
});
$('.poi-dortmund').click(function(){
	$('.stw-do-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#6FA40C');
	}
	
	$('.stw-mz-toggle,.stw-k-toggle,.stw-due-toggle,.stw-hh-toggle,.stw-da-toggle,.stw-kl-toggle').hide();
});
$('.poi-duesseldorf').click(function(){
	$('.stw-due-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#0061C8');
	}
	
	$('.stw-mz-toggle,.stw-k-toggle,.stw-hh-toggle,.stw-do-toggle,.stw-da-toggle,.stw-kl-toggle').hide();
});
$('.poi-koeln').click(function(){
	$('.stw-k-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#AF111D');
	}
	
	$('.stw-mz-toggle,.stw-hh-toggle,.stw-due-toggle,.stw-do-toggle,.stw-da-toggle,.stw-kl-toggle').hide();
});
$('.poi-mainz').click(function(){
	$('.stw-mz-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#ED8200');
	}
	
	$('.stw-hh-toggle,.stw-due-toggle,.stw-do-toggle,.stw-da-toggle,.stw-k-toggle,.stw-kl-toggle').hide();
});
$('.poi-darmstadt').click(function(){
	$('.stw-da-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#B90F22');
	}
	
	$('.stw-hh-toggle,.stw-due-toggle,.stw-do-toggle,.stw-k-toggle,.stw-mz-toggle,.stw-kl-toggle').hide();
	 return false;
});
$('.poi-koblenz-landau').click(function(){
	$('.stw-kl-toggle').fadeIn(2000);	
	if($('#tlayernav').css("overflow") == 'hidden'){
		
	}else{
		$(this).css('background-color','#0C3874');
	}
	
	$('.stw-hh-toggle,.stw-due-toggle,.stw-do-toggle,.stw-k-toggle,.stw-mz-toggle,.stw-da-toggle').hide();
	 return false;
});

/* ***** TOOLTIP-Configuration ***** */
// Use the each() method to gain access to each elements attributes
   $('a[rel]').each(function()
   {
      $
	  $(this).qtip(
      {
         content: {      		
			/*url: $(this).attr('rel'),      		
			title: {
               text: $(this).attr('alt') // Give the tooltip a title using each elements alt
              // button: 'Close' // Show a close link in the title
            }*/
			text: $(this).attr('tooltip'),
			title: {
				text: $(this).attr('alt')
			}
   		},
         position: {
            corner: {
               target: 'rightMiddle', // Position the tooltip above the link
               tooltip: 'leftTop'
            },
            adjust: {
               screen: true // Keep the tooltip on-screen at all times
            }
         },
         /*show: { 
            when: 'mouseenter', 
            solo: true // Only show one tooltip at a time
         },
         hide: 'unfocus',*/
         style: { 
		 	title: { 
				'color': '#005A66', 
				'font-size': 13,
				'overflow': 'hidden',
				'padding': 5,
				'background-color': '#D9E4E6' 
			},
		 	button: { 
				'color': 'black', 
				'font-weight': 'normal',
				'text-decoration': 'underline' 
			},
      		width: 170,
      		padding: 5,
      		background: '#ffffff',
      		color: 'black',
			fontSize: 11,
      		textAlign: 'left',
      		border: {
         		width: 1,
         		radius: 3,
         		color: '#8C8F8E'
      		},      	
      		tip: 'bottomLeft',
   		tip: true, // Give it a speech bubble tip with automatic corner detection
        name: 'cream'
		}
		
      })//.slideDown()
      
	 

   });
  
 
$('#footer a[target=_blank]').each(function()
   {      
	  // Create image content using websnapr thumbnail service
      var content = '<img src="http://images.websnapr.com/?url=';
      content += $(this).attr('href');
      content += '" alt="Loading thumbnail..." height="152" width="202" />';
      
      // Setup the tooltip with the content
      $(this).qtip(
      {
         content: content,
         position: {
            corner: {
               tooltip: 'bottomMiddle',
               target: 'topMiddle'
            }
         },
         style: {
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: 'cream'
         }
      });
   });
$('.tooltip').each(function()
   {      
	  // Setup the tooltip with the content
      $(this).qtip({
         //content: $(this).attr('tooltip'), // Use the tooltip attribute of the element for the content
         content: {      		
			    		
			title: {
               text: $(this).parent().text() // Give the tooltip a title using each elements alt
             
            },
			text: $(this).attr('tooltip')
			
   		},
		 style: { 
		 	title: { 
				'color': '#005A66', 
				'font-size': 12,
				'overflow': 'hidden',
				'padding': 5				
			},		 	
      		width: 250,
      		padding: 5,
      		background: '#ffffff',
      		color: 'black',
			fontSize: 11,
      		textAlign: 'left'      		         	
		}		
      });
   });

});

