/* ------##### 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.");
	}
}
$('.box-faq').hide();
/* ------##### EXTENSIONS / FUNCTIONS #####----- */

$.extend({
	decodeString: function(psEncodeString){
	  return unescape(psEncodeString); 
	}
});
/*$('#border-wrapper').dropShadow({
	left: 1,
	top: 0,
	blur: 3
	
});*/
$(document).ready(function(){
	var select1 = '.twtr-profile-img';
	var select2 = '.twtr-img img';	

	$(select1).attr('src','http://stellenwerk-hamburg.de/fileadmin/templates_luebeck/jobportal/img/icon_luebeck.gif');
	$(select2).attr('src','http://stellenwerk-hamburg.de/fileadmin/templates_luebeck/jobportal/img/icon_luebeck.gif');
	
	
	$('.tx-timtabsociable-pi1 img').eq(8).css("border-left","1px solid #ccc").css("padding-left","8px");	
	
	/* ----- ##### 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();					
				},1000);
			}else{
				newWin.print();
			}
			
			//newWin.close();
		}else{
			var print_rel_path = document.baseURI + $('.print_link').attr('href');
			$.get(print_rel_path, function(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);
	
	/*$('object').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();				
			}
            setTimeout(function(){
        		$('#border-wrapper').redrawShadow();
          	}, 500);
    }); */	

	$(".link-faq").hover(
			  function () {		   
			    $(this).css({cursor:'pointer'});
			  } 		  
	);

	$('.link-faq').click(function() {		
		$(this).nextUntil('.link-faq, h1, h3').slideToggle('fast');
		/*setTimeout(function(){
			$('#border-wrapper').redrawShadow();
	  	}, 500);	*/
	});

	$("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'});

	//$('.job_detail_table a[target=_blank]').text("Link");

	$('.job_detail_table a[target=_blank]').each(function (i,Option) {				
					
					if($(this).val()<30){
						//$(this).text("zur Website") ;
					}else{
						$(this).text("Link") ;
					}				
	});	

});

	
