/* ------##### TELL A FRIEND #####----- */

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.");
	}
}

/* ------##### FAQ #####----- */
$('.box-faq').hide();

/* ------##### EXTENSIONS / FUNCTIONS #####----- */

$.extend({
	decodeString: function(psEncodeString){
	  return unescape(psEncodeString); 
	}
});
$.fn.fadeToggle = function(speed, easing, callback) {
	return this.animate({opacity: 'toggle'}, speed, easing, callback);  
};

/* ------##### AFTER DOM LOADING #####----- */

$(document).ready(function(){
	$('.tx-timtabsociable-pi1 img').eq(8).css("border-left","1px solid #ccc").css("padding-left","8px").css("opacity","1");											
/* ------##### TELL A FRIEND #####----- */
	if($('.sendAFriendLinkPopup').length > 0){
		var url = $(".sendAFriendLink").attr("href");
		$(".sendAFriendLink").remove();
		
		$(".sendAFriendLinkPopup").removeAttr("href");
		$(".sendAFriendLinkPopup").removeAttr("onclick");
		$(".sendAFriendLinkPopup").removeAttr("onkeypress");
		$(".sendAFriendLinkPopup").removeClass("sendAFriendLinkPopup").addClass("sendAFriendLink");		
		
		url = url.split('?tipUrl=');
		var ajaxPath = url[0];
		var ajaxParam = $.decodeString(url[1]);		
		
		$(".sendAFriendLink, input[type=button]").hover(
			function () {			    
			    $(this).css({cursor:'pointer'});			} 
		);
		$(".sendAFriendLink ").text('');	
		
		$(".sendAFriendLink").click(function(){		
			$.ajax({					
				url:ajaxPath,
				type: "GET",					
				data: {tipUrl:ajaxParam},
				dateType: 'html',
				beforeSend: function() {
					$('#services').after('<input type="hidden" name="ajaxUrl" value="'+ ajaxPath + '">');					
					/*
					if($.browser.msie){
						
						$('#overlay').css( {opacity:0.7,backgroundColor:'black'});
						$('#overlay').fadeIn(3000);
							
							
						
					}else{
						$('#overlay').toggle();
						$('#overlay').animate( {opacity:0.7,backgroundColor:'black'}, 3000 );
						
					}*/
				},
				// Es hat funktioniert?
				success: function(data) {				
						$("#tipForm").html(data);	
						
						if($.browser.msie){
							$("#tellfriend").fadeToggle('slow');								
						}else{
							//$("#tellfriend").fadeToggle('slow').corner("6px");	
							$("#tellfriend").fadeToggle('slow');
						}
						$('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");
				}
			});		
		});	
	} 

});
/* ------##### AD CONTROL #####----- */	


setTimeout(function(){
	if(!$.browser.msie){
		$('object').parent().prepend("<div class='ad_info' style='color:#999;font-size:10px;'>Anzeige</div>");
	}else{
		
	}
	//$('span span object').parent().parent().prepend("<div style='color:#999;font-size:10px;'>Anzeige</div>");
	$('.banner a img').each(function() {
        if ( $(this).width() > 1 ) {				
            $(this).parents('.banner').prepend("<div style='color:#999;font-size:10px; '>Anzeige</div>");
        }else{
			//$('.banner').hide();				
		}
	}); 
	$('#video object').each(function() {
        if ( $(this).width() > 1 ) {	
        	$('.ad_info').remove();
            $(this).parents('#video ').prepend("<div style='color:#999;font-size:10px; '>Video</div>");
        }else{
			//$('.banner').hide();				
		}
	}); 
	
},2000);
/* ------##### TWITTER #####----- */	

$('.twtr-hd h3').text("Best offers, Tipps und Infos") ;

/* ------##### FAQ #####----- */	

$(".link-faq").hover(
		  function () {		    
		    $(this).css({cursor:'pointer'});
		  } 		  
);
$('.link-faq').click(function() {
	$(this).nextUntil('.link-faq, h1, h3').slideToggle('fast');
	
});

/* ------##### DUE PRIVATE/INTERN SWITCH #####----- */	

if($('h1').parents().andSelf().find('base').attr('href') == 'http://www.stellenwerk-duesseldorf.de/'){
	if($('.job_preview_table .ang_table_zeile_1:contains(INTERN)').text() == 'INTERN'){        
		$('h1:contains(Private)').text('Uni-interne Anzeige aufgeben') ;
	}
	$('#type_uni').click(function(){
		if($('#type_uni').is(':checked')){       
			$('h1:contains(Private)').text('Uni-interne Anzeige aufgeben') ;
		}
	});
	$('#type_privat').click(function(){
		if($('#type_privat').is(':checked')){      
			$('h1:contains(interne)').text('Private Anzeige aufgeben') ;
		}
	});
	
	if($('p:contains(Team)').text() == 'Ihr Stellenwerk-Team'){  	   
		$('h1:contains(Anzeige)').text('Ihre Anzeige ist bei uns eingegangen')
	}
}




/* ------##### TEXT COUNTER #####----- */	

$("textarea#tx_exinitjobexchange_pi2_products_")
		.dodosTextCounter(240, {counterDisplayClass: "textcounter-products",addLineBreak:true});
$("textarea#tx_exinitjobexchange_pi2_locations_")
		.dodosTextCounter(240, {counterDisplayClass: "textcounter-locations",addLineBreak:true});
$("textarea#tx_exinitjobexchange_pi2_description_")
		.dodosTextCounter(500, {counterDisplayClass: "textcounter-description",addLineBreak:true});
$("textarea#tx_exinitjobexchange_pi2_lookingfor_")
		.dodosTextCounter(400, {counterDisplayClass: "textcounter-lookingfor",addLineBreak:true});

$(".textcounter-products,.textcounter-locations,.textcounter-description,.textcounter-lookingfor")
	.after(" Zeichen verbleiben")
	.css({'font-weight' : 'bold', 'font-style' : 'italic', 'padding-left' : '5px', 'font-family' : 'Arial'});

/* ------##### LINK MANIPULATION #####----- */

$('.job_detail_table a[target=_blank]').each(function (i,Option) {				
				
				if($(this).val()<30){
					//$(this).text("zur Website") ;
				}else{
					$(this).text("Link") ;
				}				
});		