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

UTF8 = {
	    encode: function(s){
	        for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
	            s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
	        );
	        return s.join("");
	    },
	    decode: function(s){
	        for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
	            ((a = s[i][c](0)) & 0x80) &&
	            (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
	            o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
	        );
	        return s.join("");
	    }
	};

/* ------##### 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(){
/* ----- ##### TWITTER LIST ##### ----- */	
	
	//$('.stw-hh-twitter').hide();
	//$('.stw-hh-twitter').fadeIn(3000).html('<a class="fb_share_link" name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php?u='+url+'&t='+title+'">Teilen</a>');
	//$.getScript('http://widgets.twimg.com/j/2/widget.js');
	
	
	
	/* ----- ##### TWITTER RETWEET BUTTON ##### ----- */
	var title = escape(document.title);	
	var _url=window.location.href;
	var _url=_url.replace(/((?:\?|&)?fbc_receiver=.+)?(?:#.*)?$/,"");
	var url=escape((typeof tweetmeme_url=="string")?tweetmeme_url:((typeof TWEETMEME_URL=="string")?TWEETMEME_URL:_url)).replace(/\+/g,"%2b");
	var source=(typeof tweetmeme_source=="string")?escape(tweetmeme_source):((typeof TWEETMEME_SOURCE=="string")?escape(TWEETMEME_SOURCE):false);
	var style=(typeof tweetmeme_style=="string")?escape(tweetmeme_style):((typeof TWEETMEME_STYLE=="string")?escape(TWEETMEME_STYLE):"normal");
	var service=(typeof tweetmeme_service=="string")?escape(tweetmeme_service):((typeof TWEETMEME_SERVICE=="string")?escape(TWEETMEME_SERVICE):false);
	var service_api=(typeof tweetmeme_service_api=="string")?escape(tweetmeme_service_api):((typeof TWEETMEME_SERVICE_API=="string")?escape(TWEETMEME_SERVICE_API):false);
	var alias=(typeof tweetmeme_alias=="string")?escape(tweetmeme_alias):((typeof TWEETMEME_ALIAS=="string")?escape(TWEETMEME_ALIAS):false);
	var hashtags=(typeof tweetmeme_hashtags=="string")?escape(tweetmeme_hashtags):((typeof TWEETMEME_HASHTAGS=="string")?escape(TWEETMEME_HASHTAGS):false);
	var space=(typeof tweetmeme_space=="number")?escape(tweetmeme_space):((typeof TWEETMEME_SPACE=="number")?escape(TWEETMEME_SPACE):false);
	var width=(typeof tweetmeme_width=="number")?escape(tweetmeme_width):((typeof TWEETMEME_WIDTH=="number")?escape(TWEETMEME_WIDTH):false);
	var src="http://api.tweetmeme.com/button.js";
	
	switch(style){
		case"compact":
			var h=20;
			var w=90;
			break;
		default:
			var h=61;
			var w=50;
			break
	}
	if(width){
		w=width
	}
	src+="?url="+url;src+="&style="+style;
	if(source!=false){
		src+="&source="+source
	}
	if(service){
		src+="&service="+service
	}
	if(service_api){
		src+="&service_api="+service_api
	}
	if(alias){
		src+="&alias="+alias
	}
	if(hashtags){
		src+="&hashtags="+hashtags
	}
	if(space){
		src+="&space="+space
	}
	//document.write('<iframe src="'+src+'" height="'+h+'" width="'+w+'" frameborder="0" scrolling="no"></iframe>');
	//alert(url);
	$('.twitter').hide();
	$('.twitter').fadeIn(4000).html('<iframe allowTransparency="true" src="'+src+'" height="'+h+'" width="'+w+'" frameborder="0" scrolling="no"></iframe>');
	tweetmeme_url=null;
	TWEETMEME_URL=null;
	tweetmeme_source=null;
	TWEETMEME_SOURCE=null;
	tweetmeme_service=null;
	TWEETMEME_SERVICE=null;
	tweetmeme_service_api=null;
	TWEETMEME_SERVICE_API=null;
	tweetmeme_style=null;
	TWEETMEME_STYLE=null;
	tweetmeme_alias=null;
	TWEETMEME_ALIAS=null;
	tweetmeme_hashtags=null;
	TWEETMEME_HASHTAGS=null;
	tweetmeme_space=null;
	TWEETMEME_SPACE=null;
	
	/* ----- ##### FACEBOOK SHARE / LIKE ##### ----- */
		
	$('.fb_share').hide();
	$('.fb_share').fadeIn(3000).html('<a class="fb_share_link" name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php?u='+url+'&t='+title+'">Teilen</a>');
	$.getScript('http://static.ak.fbcdn.net/connect.php/js/FB.Share');
	setTimeout(function(){				    
		$('span').removeClass('fb_share_no_count');	
		$('.fb_share a').css({'display':'inline','width':'auto'});
	},1000);
		
	$('.fb_like').hide();
	$('.fb_like').fadeIn(5000).html('<iframe src="http://www.facebook.com/plugins/like.php?href='+url+'&amp;layout=button_count&amp;show_faces=true&amp;width=110&amp;action=recommend&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style=" display:none;" allowTransparency="true"></iframe>');
	$('.fb_like iframe').css({'border':'none','overflow':'hidden','width':'110px','height':'21px'});
		
	/* ----- ##### SERVICE TOOLTIPS ##### ----- */
	$(".services span>a[title]").tooltip(
		{
			offset: [1, 2],
			position: ['top', 'center'],
			effect: 'slide'
		}).dynamic(
		{ 
			bottom: { direction: 'down', bounce: true } 
		}); 
		
	$('.tx-timtabsociable-pi1 img').eq(8).css("border-left","1px solid #ccc").css("padding-left","8px").css("opacity","1");											
	
	/* ----- ##### BOOMARKING ##### ----- */	
	
	$('.bookmark_link,.tellafriend, .fb_like iframe').show();
	/*$('.tellafriend_link').show();*/
	
	$(".bookmark_link, .add_favorite, .close").hover(
			function () {			    
			    $(this).css({cursor:'pointer'});
			} 
		);
	
	$('.bookmark_link,.close').click(function(){
		$('.bookmark_box').toggle();
	});
	$('.bookmark_box li a').hover(
			// on mouse over move to left
	    function() {
	    	$(this).stop().animate({ paddingLeft: '20px' },300);
  },
  // on mouse out, move back to original position
  	function() {
	  	$(this).stop().animate({ paddingLeft: '0px' }, 300);
    });
	
	if($.browser.opera || $.browser.webkit) {		
		$("ul.left li:first-child ").remove();		
		$("ul.left").append($("ul.right li:first-child "));		
		if($.browser.webkit){
			//$("ul.right li:first-child ").remove();			
		}else{
			$('.right').css({'width':'120px'});
		}
	}

	$("a.add_favorite").click(function(event){
		event.preventDefault(); // prevent the anchor tag from sending the user off to the link
		
		var url = window.location.href;
		var title = document.title;
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else { // for Safari, Konq etc - browsers who do not support bookmarking scripts (that i could find anyway)
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}

	});
	
	/* ----- ##### PRINT SERVICE ##### ----- */
	
	//alert($(this).parents().andSelf().find('base').attr('href'));
	$('.print_link').click(function(){		
		if($.browser.msie || $.browser.opera){
			var print_rel_path = $(this).parents().andSelf().find('base').attr('href') + $('.print_link').attr('href');
			newWin = window.open(print_rel_path,"Druckvorschau");				
			if($.browser.opera){
				setTimeout(function(){				    
					newWin.print();		
					newWin.close();
				},1000);
			}else{
				newWin.print();		
				setTimeout(function(){						
					newWin.close();
				},1000);
			}
			
			//newWin.close();
		}else{
			var print_rel_path = document.baseURI + $('.print_link').attr('href');
			newWin = window.open(print_rel_path,"Druckvorschau");
			setTimeout(function(){				    
				newWin.print();	
				newWin.close();	
			},1000);			
			
			/*$.get(print_rel_path, function(data){			
				console.log(data);
				newWin = window.open("");		
				newWin.document.write(data);
				newWin.print();
				//newWin.close();			
			});*/
		}	
		return false;
	});
	
	/* ----- ##### 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");
		//$(".sendAFriendLink").prepend("<img src='fileadmin/img/sendAFriend.png' style='margin-right:3px;'></img>");
		
		url = url.split('?tipUrl=');
		var ajaxPath = url[0];
		var ajaxParam = $.decodeString(url[1]);		
		
		$(".sendAFriendLink, input[type=button]").hover(
			function () {			    
			    $(this).css({cursor:'pointer'});
			} 
		);		
		
		$(".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').css( {backgroundColor:'black'});
						$('.overlay').animate( {opacity:0.7,backgroundColor:'black'}, 3000 ); /* that needs the color plugin*/
						$('.overlay').animate( {opacity:0.7}, 3000 ); 
						
					}
				},
				// Es hat funktioniert?
				success: function(data) {				
						$("#taf_content").html(data);	
						
						if($.browser.msie){
							$("#tellfriend").fadeToggle('slow');	
							//$("#tellfriend").animate({opacity: 'toggle'}, 'slow');
						}else{
							//$("#tellfriend").fadeToggle('slow').corner("6px");	
							$("#tellfriend").fadeToggle('slow');
							//$("#tellfriend").animate({opacity: 'toggle'}, 'slow');							
						}
						$('input#close').click(function() {
							$("#tellfriend").animate({opacity: 'toggle'}, 'slow');
					    	$("input[name=ajaxUrl]").remove();
					    	$(".overlay").animate( {opacity:0.0}, 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");
				}
			});		
		});	
	} 

});

/* ----- ##### ADVERTISING STUFF ##### ----- */


setTimeout(function(){
	$('object').parent().prepend("<div style='color:#999;font-size:10px;'>Anzeige</div>");
	//$('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();				
		}
	}); 
	
},2000);

/* ----- ##### VIDEO EFFECTS ##### ----- */

$('#video').hide();
$("a.video").removeAttr('href');
$("a.video").hover(function() {$(this).css({cursor: 'pointer'});});
$('a.video').click(function() {
	if($('#video').is(':visible')){
		var linkText = 'Video ansehen';
	}
	if($('#video').is(':hidden')){
		var linkText = 'Video ausblenden';
	}
	$('#video').slideToggle('fast'); 
	$("#video>div").remove();
	$("a.video").text(linkText);
});

/* ----- ##### TWITTER MANIPULATION ##### ----- */
$('.twtr-hd h3').text("Best offers, Tipps und Infos") ;	

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

$(".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')
	}
}

$(".profile_list_item").hover( function(){	
	$(this).parent().find('div').css({height: "100%"});		
	if($(this).parent().find('div:eq(0)').height() < $(this).parent().find('div:eq(1)').height()){
		var maxheight = $(this).parent().find('div:eq(1)').height();
	}else{
		var maxheight = $(this).parent().find('div:eq(0)').height();
	}
	if(maxheight < $(this).parent().find('div:eq(2)').height()){
		var maxheight = $(this).parent().find('div:eq(2)').height();
	}	
	$(this).parent().find('div').css({height: "25px"});
	
	$(this).parent().find('div').stop().animate({height: maxheight},{queue:true,duration:1000});
}, 	function(){
	$(this).parent().find('div').stop().animate({height: "25px"},{queue:false,duration:500});
	});
	


/* ------##### TEXT COUNTER #####----- */	
// ------ Firmenportraits
$("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});
// ------ Studentenprofile
$("input#tx_uhhmgstudentsdb_pi1_field_of_study_")
		.dodosTextCounter(60, {counterDisplayClass: "textcounter-field_of_study",addLineBreak:true});
$("textarea#tx_uhhmgstudentsdb_pi1_desired_initial_range_")
	.dodosTextCounter(60, {counterDisplayClass: "textcounter-desired_initial_range",addLineBreak:true});
$("textarea#tx_uhhmgstudentsdb_pi1_practical_experience_")
	.dodosTextCounter(80, {counterDisplayClass: "textcounter-practical_experience",addLineBreak:true});

$(".textcounter-products,.textcounter-locations,.textcounter-description,.textcounter-lookingfor,.textcounter-field_of_study,.textcounter-desired_initial_range,.textcounter-practical_experience")
	.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") ;
				}				
});		