var _MouseX = 0;
var _MouseY = 0;
var _link = "";


var _ie = document.all;

jQuery(document).ready(function() {
	document.title = "dasKonzept - Verein";
	
	/*jQuery("#pro-oben").hover(
	function () {
		jQuery("#pro-oben").stop(true,true);
	},
	function () {
		startProjekte();
		}
	);
	*/
	/*jQuery("#oben").find("#pro-oben").find("a").each(function() {
		pro-width = pro-width + 100;
	});
	jQuery("#pro-oben").css('width',pro-width);*/
});

jQuery(window).load(function() { 
	startProjekte();
});

function startProjekte() {
	hidden = document.getElementById('pro-oben').offsetWidth; /* jQuery("#partner").width(); !opera*/
	hidden = hidden - 340; 
	jQuery("#pro-oben").animate({marginLeft:"-"+hidden},20000,"linear",function() {
		jQuery("#pro-oben").animate({marginLeft:"0px"},20000,"linear",startProjekte);
	});


}


function loadContent(contentId, title) {
	jQuery("#content").fadeOut(100);
	jQuery("#aktuell").hide();
	new Ajax.Updater('content', '/system/content.php', {
		method: 'get', 
		parameters: 'content='+contentId, 
		onComplete: function() { 				
			jQuery('#content').fadeIn();
			document.getElementById("content").scrollTop = 0;
			pageTracker._trackPageview("/index.php?content="+contentId); /* google analytics - ajax */
		}
	});
	
}

function loadProjekt(projektId,title) {
	if(!title) var title = document.title;
	jQuery("#content").fadeOut(100);
	new Ajax.Updater('content', '/system/content.php?content=31' , {
		method: 'get',
		parameters: 'projekt='+projektId,
		evalScripts: true,
		onComplete: function() {
			jQuery('#content').fadeIn();
			document.getElementById("content").scrollTop = 0;
			pageTracker._trackPageview("/index.php?content=31&projekt="+projektId); /* google analytics - ajax */
		}	
	});
}

function loadGalerie(gid) {
	/*jQuery("#content").fadeOut(100);
	new Ajax.Updater('content','system/content.php?content=41', {
		method: 'get',
		parameters: {galerie: gid},
		onComplete: function() {
			jQuery('#content').fadeIn();
			document.getElementById("content").scrollTop = 0;
		}	
	});*/
	title = "Galerie - "+gid;
	new Ajax.Updater('boxcontent','/system/content.php?content=41', {
		method: 'get',
		parameters: {galerie: gid},
		onComplete: function() {
			document.getElementById("boxcontent").scrollTop = 0;
			pageTracker._trackPageview("/"+title); /* google analytics - ajax */
		}
	});
}

function loadFoto(fid,gid) {	
	/*jQuery("#img").fadeOut(100);
	new Ajax.Updater('content', 'system/content.php?content=42', {
		method: 'get',
		parameters: {foto: fid, galerie: gid},
		onComplete: function() {
			jQuery('#img').fadeIn();
			document.getElementById("content").scrollTop = 0;
		}	
		});	*/
	title = "Foto - "+fid;
	new Ajax.Updater('boxcontent', '/system/content.php?content=42',{
		method: 'get',
		parameters: {foto: fid, galerie: gid},
		onComplete: function() {
			document.getElementById("boxcontent").scrollTop = 0;
			pageTracker._trackPageview("/"+title); /* google analytics - ajax */
		}
	});
}

function readmore(nid) {
	jQuery("#"+nid).find(".leadin").hide(1);
	jQuery("#"+nid).find(".text").show();
}

function slideSub(direction) {
	margin = jQuery("#sub-projekte").find("#t").css("marginTop");
	margin = margin.substr(0, margin.length-2);
	scroll = parseInt(margin);
	if(direction == 'up' ){
		if(scroll != 0)
			jQuery("#sub-projekte").find("#t").animate({marginTop:scroll+362+"px"},400,"linear");
	}
	else if(direction == 'down') {
			jQuery("#sub-projekte").find("#t").animate({marginTop:scroll-362+"px"},400,"linear");
		
	}

}

function openShare(link) {
	_link = link;
	twitter = jQuery("#share-box").find(".twitter").attr("href");
	twitter = twitter+encodeURIComponent(_link);
	jQuery("#share-box").find(".twitter").attr("href",twitter);
	
	google = jQuery("#share-box").find(".google-buzz-button").attr("href");
	google = google+encodeURIComponent(_link);
	jQuery("#share-box").find(".google-buzz-button").attr("data-url",google);
	
	fb = jQuery("#share-box").find(".fb").attr("href");
	fb = fb+encodeURIComponent(_link);
	jQuery("#share-box").find(".fb").attr("href",fb);
	
	fblike = jQuery("#share-box").find(".fblike").attr("src");
	fblike = fblike+encodeURIComponent(_link);
	jQuery("#share-box").find(".fblike").attr("src",fblike);
	
	jQuery("#share-box").find("input").val(link);
	jQuery("#share-box").fadeIn();


}

function guestbookEntry(){
	var name = document.getElementById("eman").value;
	var email = document.getElementById("liame").value;
	var text = document.getElementById("txet").value;
	var aha = document.getElementById("aha").value;
	
	if(name == ""){
		alert("Fehler! Bitte einen Namen angeben!");
		return;
	}
	if(text == ""){
		alert("Fehler! Bitte einen Text eingeben!");
		return;
	}
	
	new Ajax.Request( '/system/content.php?content=7&new=1', {
		method: 'post', 
		parameters:{name: name, email: email, text: text, aha: aha},
		onComplete: function(req) {
			ret = req.responseText;
			ret = parseInt(ret);/* return wert von ajax.request */
			if(ret == 1) {
				loadContent(7);
			}
			else {
				err = 'Fehler beim Eintragen, bitte nochmal versuchen.';
				jQuery("#content").html = err;
			}		
		}
		}
	);
}

function user(){
head('<script type="text/javascript" src="/system/tinymce/tiny_mce.js" ></script>');
/*tinyMCE.init({
	mode : "none", 
	width: "331px",
	height: "113px",
	theme : "simple" 
});*/
head('<script type="text/javascript" src="/user/js/user.js" ></script>');
OpenBox('User-Bereich', '/user/login.php');
		tinyMCE.init({
	mode : "none", 
	theme : "simple" 
});
}

function head(str) { /* user login - index.php */
	jQuery('head').append(str);

}

function preload(art) {
/*if(art == "foto") {*/
	jQuery('#boxcontent').find('#img').find('p').hide();
	jQuery('#boxcontent').find('#img').find('img').show();
/*}
else if (art == "galerie") {
jQuery('#boxcontent').find('p.lade').hide();
jQuery('#boxcontent').find('ul.fotos').show();	
}*/
}

function showBandInfo(band) {
	if(_MouseX > (document.getElementsByTagName('html')[0].clientWidth / 2))
		x = _MouseX - 500;
	else
		x = _MouseX;
		
	if(_MouseY > (document.getElementsByTagName('html')[0].clientHeight - 153))
		y = _MouseY - 153;
	else
		y = _MouseY;
		
	jQuery("#info"+band).css("top",y+"px");
	jQuery("#info"+band).css("left",x+"px");
	jQuery("#info"+band).toggle();
}

function showMsg(msg) {
	document.getElementById("msg").innerHTML = msg;
}

function delNews(id){	
	if(confirm("News-Eintrag wirklich löschen?"))
		document.location.href = "index.php?i=admin&a=editnews&s=del&id=" + id;
}

function delCat(id) {
	if(confirm("Kategorie wirklich löschen?"))
		document.location.href = "index.php?i=admin&a=editgallery&s=del&id=" + id;
}

function browser(name){  
	var agent = navigator.userAgent.toLowerCase();  
	if (agent.indexOf(name.toLowerCase())>-1) {  
		return true;  
	}  
	return false;  
}  
