jQuery(document).ready(function() {
	var oldSearchStr;
	jQuery('#gallery_submit input[type=text], #gallery_submit input[type=email]').click(function() {
	  oldSearchStr = jQuery(this).val();
	  jQuery(this).val('');
	});
	jQuery('#gallery_submit input[type=text], #gallery_submit input[type=email]').blur(function() {
	  if(jQuery(this).val() == "") {
	    jQuery(this).val(oldSearchStr);
	  }
	});
	jQuery('#gallery_submit').submit(function() {
		if(jQuery('input[name=image_vote]:checked').length==0) {
		  jQuery('#gallery_notice').show();
		  return false;
		} else if(jQuery('input[name=acceptnewsletter]:checked').length==0) {
			jQuery('#gallery_notice').show();
		  return false;
		} else if(jQuery('#gallery_submit input[name=email]').val()=="" || jQuery('#gallery_submit input#username').val()=="Username" || jQuery('#gallery_submit input#username').val()=="") {
		  jQuery('#gallery_notice').show();
		return false;
		} else {
			var pid = jQuery('input[name=image_vote][type=radio]:checked').val();
			var emailPost = jQuery('#gallery_submit input[type=email]').val();
			var firstname = jQuery('#gallery_submit input#firstname').val();
			var lastname = jQuery('#gallery_submit input#name').val();
			var gid = jQuery('#gallery_submit input[name=gid]').val();
			jQuery.ajax({
			   type: "GET",
			   url: remote,
			   data: "pid="+pid+"&r=1" + "&username="+encodeURIComponent(lastname) + "&firstname="+encodeURIComponent(firstname) + "&email="+encodeURIComponent(emailPost),
			   success: function(msg){
           setCookie('gz_votedImage', '1', '1');
           setCookie('gz_votedImagePostID', gid, '1');
				   window.location = remote;
			   }
			 });
		  return false;
		}
		return false;
	 });
	if (jQuery.browser.mozilla == true) {
		jQuery('.menu li li a, #head .menu li li a:link, #head .menu li li a:visited').css({'margin' : '6px 10px 0px'});
		jQuery('#head .menu li li a, #head .menu li li a:link, #head .menu li li a:visited').css({'padding' : '4px 6px 6px'});
	}
	jQuery('.entry, .spoiler').find('a').each(function() {
		var oldCssObj = {
			'text-decoration' : 'none',
			'border-bottom'	: '1px dotted #3C70A7',
			'font-style' : 'normal'		
		}
		var internalLinksAttribute = jQuery(this).attr('href');
		var searchObj=/gruenderszene/i;
		if(internalLinksAttribute.match(searchObj) == "gruenderszene" && jQuery(this).html() != 'Weiterlesen »') {
			jQuery(this).css(oldCssObj);
		}
	});
	jQuery('.entry, .spoiler').find('a').hover(function() {
		var internalLinksAttribute = jQuery(this).attr('href');
		var searchObj=/gruenderszene/i;
		if(internalLinksAttribute.match(searchObj) == "gruenderszene" && jQuery(this).html() != 'Weiterlesen »') {
			var newCssObj = {
				'text-decoration' : 'none',
				'border-bottom'	: '1px dotted #3C70A7'		
			}
			jQuery(this).css(newCssObj);
		} else {
			return false;
		}
	}, function() {
		var oldCssObj = {
			'font-style' : 'normal'		
		}
		jQuery(this).css(oldCssObj);
	});
	if(jQuery('.menu > li.current-menu-parent').length == 0 && jQuery('.menu > li.current-menu-item').length == 0) {
		if(jQuery('#menu-international-2').length == 1) {
			jQuery('#menu-item-31746').addClass('current-menu-parent');
			
			if(jQuery('#menu-international-2 .current-menu-parent').length == 0) {
				jQuery('#menu-item-20760').addClass('current-menu-parent');
			}
			//jQuery('#menu-item-20027 ul li').first().addClass('current-menu-item');
		} else {
			jQuery('.menu > li').first().addClass('current-menu-parent');
			
			if(jQuery('.menu li.current-post-ancestor').length == 0 && jQuery('.menu li.current-category-ancestor').length == 0) {
				jQuery('.menu > li ul li').first().addClass('current-menu-item');
			}
		}
	}
	jQuery('.landing-topic a.more-articles').click(function() {
		var href=jQuery(this).attr('href');
		href = href.replace(/#/g, '');
		landingPageLoadMoreFeeds(href);
		return false;
	});
	if(is_international == 1) {
		var search_hint = 'Search';
	}
	else {
		var search_hint = 'Suchbegriff';
	}
	
	var search = jQuery('#searchform #sourceInput');
	
	if(search.val() == '') {
		search.val(search_hint);
	}
	search.focus(function() {
		if(search.val() == search_hint) {
			search.val('');
		}
	});
	search.blur(function() {
		if(search.val() == '') {
			search.val(search_hint);
		}
	});
	// SexyBookmarks Title Tags
	if(is_international == 1) {
		if (jQuery.browser.mozilla == true) {
			jQuery('.menu li li a, #head .menu li li a:link, #head .menu li li a:visited').css({'margin' : '6px 10px 0px'});
			jQuery('#head .menu li li a, #head .menu li li a:link, #head .menu li li a:visited').css({'padding' : '4px 6px 5px'});
		} 
		jQuery('.shr-bookmarks ul li.shr-facebook a').attr('title', 'Share this post on Facebook');
		jQuery('.shr-bookmarks ul li.shr-twitter a').attr('title', 'Tweet this post');
		jQuery('.shr-bookmarks ul li.shr-linkedin a').attr('title', 'Share this post on LinkedIn');
		jQuery('.shr-bookmarks ul li.shr-mail a').attr('title', 'Share this post via E-Mail');
		jQuery('.shr-bookmarks ul li.shr-comfeed a').attr('title', 'Subscribe to RSS Feed');
		jQuery('.shr-bookmarks ul li.shr-delicious a').attr('title', 'Bookmark this post on Delicious');
		jQuery('.shr-bookmarks ul li.shr-misterwong a').attr('title', 'Bookmark this post on Mister Wong');
		jQuery('.FBConnectButton_Text').html('Share');
		
		// SidebarBookmarks Title Tags
		jQuery('#sidebar a#sb-facebook').attr('title', 'Be a fan on Facebook');
		jQuery('#sidebar a#sb-twitter').attr('title', 'Follow on Twitter');
		jQuery('#sidebar a#sb-rss').attr('title', 'Subscribe to RSS Feed');
		
		// Category Title Tags
		var gerValToEnglishValCategory = jQuery('a[rel=category tag]').attr('title');
		switch (gerValToEnglishValCategory) {
			case 'Alle Artikel in General ansehen':
				jQuery('a[rel=category tag]').attr('title', 'Show all articles in General');
				break;
			case 'Alle Artikel in Expert Articles ansehen':
				jQuery('a[rel=category tag]').attr('title', 'Show all articles in Expert Articles');
				break;
			case 'Alle Artikel in News ansehen':
			case 'Alle Artikel in News  ansehen':
				jQuery('a[rel=category tag]').attr('title', 'Show all articles in News');
				break;
			case 'Alle Artikel in Interviews ansehen':
			case 'Alle Artikel in Interviews  ansehen':
				jQuery('a[rel=category tag]').attr('title', 'Show all articles in Interviews');
				break;
		}
		var CommentsValGerToEng = jQuery('.meta a').val('No Comments');
		for (var a=0; a<CommentsValGerToEng.length; a++) {
			var CommentsValGerToEngObj = CommentsValGerToEng[a];
			var GerTitle = jQuery(CommentsValGerToEngObj).attr('title');
			var EnglishTitle = GerTitle.replace(/Kommentiere/g, 'Leave a comment to');
			jQuery(CommentsValGerToEngObj).attr('title', EnglishTitle);
		}
		jQuery('a[title=Impressum]').attr('title', 'Legal Notice');	
	}
});
function landingPageLoadMoreFeeds(id) {
	var i = 0;
	var showElements = jQuery('#topic_' + id + '.landing-topic ul li[style]');
	while(i<6) {
		jQuery(showElements[i]).removeAttr('style').show();
		console.log(showElements[i]);
		if(jQuery('#topic_' + id + '.landing-topic ul li[style]').length==0) {
			jQuery('#topic_' + id + '.landing-topic a.more-articles').hide(); 
		}
		i=i+1;
	}
}
function sendMailTo(name, company) {
  	locationstring = 'mai' + 'lto:' + name + '@' + company;
  	window.location.replace(locationstring);
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (
			anchor.getAttribute("href") && ( 
			anchor.getAttribute("rel") == "external" || 
			anchor.getAttribute("rel") == "external nofollow" || 
			anchor.getAttribute("rel") == "external follow" ||
			anchor.getAttribute("rel") == "nofollow external" )
			)
		anchor.target = "_blank";
	}
}

function toggleContentRight() {
  var contentId = document.getElementById("gesellschaftsstruktur");
  var contentId2 = document.getElementById("gesellschaftsverteilung");
  
  if (contentId.style.display == "block") {
  	contentId.style.display = "none";
  	contentId2.style.display = "block";
  }
  
}
function toggleContentLeft() {
  var contentId = document.getElementById("gesellschaftsstruktur");
  var contentId2 = document.getElementById("gesellschaftsverteilung");
  
  if (contentId2.style.display == "block") {
  	contentId.style.display = "block";
  	contentId2.style.display = "none";
  }
  
}
function toggleNamefield() {
  var contentId = document.getElementById("sort-by-name");
  var contentId2 = document.getElementById("sort-by-value");
  
  if (contentId.style.display == "block") {
  	contentId.style.display = "none";
  	contentId2.style.display = "block";
  }
  
}
function toggleValuefield() {
  var contentId = document.getElementById("sort-by-name");
  var contentId2 = document.getElementById("sort-by-value");
  
  if (contentId2.style.display == "block") {
  	contentId.style.display = "block";
  	contentId2.style.display = "none";
  }
  
}

function insert(input, aTag, eTag) 
{
    input.focus();
    if(!aTag) return;
    if(!eTag) eTag = '';

    if(typeof document.selection != 'undefined') 
    {
         var range = document.selection.createRange();
         var insText = range.text;
         if(!insText && eTag) return alert('Nichts markiert!');
         range.text = aTag + insText + eTag;
         range = document.selection.createRange();
         if (insText.length == 0)  range.move('character', -eTag.length);
         else  range.moveStart('character', aTag.length + insText.length + eTag.length);
         range.select();
    }
    else if(typeof input.selectionStart != 'undefined')
    {
         var start = input.selectionStart;
         var end = input.selectionEnd;
         var insText = input.value.substring(start, end);
         if(!insText && eTag) return alert('Nichts markiert!');
         input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
         var pos;
         if (insText.length == 0)  pos = start + aTag.length;
         else pos = start + aTag.length + insText.length + eTag.length;
         input.selectionStart = pos;
         input.selectionEnd = pos;
    }
    else
    {
         alert('Leider unterstützt dein Browser nicht die notwendige Funktion!');
    }
}

// Cookies

function getCookie(c_name) {
  if (document.cookie.length>0) {
  	c_start=document.cookie.indexOf(c_name + "=");
  	if (c_start!=-1) { 
      c_start=c_start + c_name.length+1 ;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length
    	return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return ""
}
function setCookie(c_name,value,expiredays) {
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toUTCString());
}
function checkCookie() {
  votedImage=getCookie('votedImage');
  if (votedImage!="") {
	return 0;
  } else {
	return 1;
  }
}

/*
Dynamic Version by: Nannette Thacker
http://www.shiningstar.net
Original by :  Ronnie T. Moore
Web Site:  The JavaScript Source
Use one function for multiple text areas on a page
Limit the number of characters per textarea
*/

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

