/* Javascript Core for Getipa.info 
	Copyright to typhoch2 for Getipa.info 
 */

jQuery(document).ready(function() {

	( function( jQuery ) {
		 
	    // plugin definition
	    jQuery.fn.overlabel = function( options ) {
	 
	        // build main options before element iteration
	        var opts = jQuery.extend( {}, jQuery.fn.overlabel.defaults, options );
	 
	        var selection = this.filter( 'label[for]' ).map( function() {
	 
	            var label = jQuery( this );
	            var id = label.attr( 'for' );
	            var field = document.getElementById( id );
	 
	            if ( !field ) return;
	 
	            // build element specific options
	            var o = jQuery.meta ? jQuery.extend( {}, opts, label.data() ) : opts;
	 
	            label.addClass( o.label_class );
	 
	            var hide_label = function() { label.css( o.hide_css ) };
	            var show_label = function() { this.value || label.css( o.show_css ) };
	 
	            jQuery( field )
	                 .parent().addClass( o.wrapper_class ).end()
	                 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
	 
	            return this;
	 
	        } );
	 
	        return opts.filter ? selection : selection.end();
	    };
	 
	    // publicly accessible defaults
	    jQuery.fn.overlabel.defaults = {
	 
	        label_class:   'overlabel-apply',
	        wrapper_class: 'overlabel-wrapper',
	        hide_css:      { 'text-indent': '-10000px' },
	        show_css:      { 'text-indent': '0px', 'cursor': 'text' },
	        filter:        false
	 
	    };
	 
	} )( jQuery );
	
	jQuery("label.overlabel").overlabel();

jQuery('#offon').val(0);
	
	
//catButton
	jQuery("#catButton").click(function(){
		var offon = parseInt(jQuery('#offon').val());
		if (offon==0) {
			jQuery('#offon').val(1);
			jQuery("#categoriesmenu").hide("fast");
			jQuery(".littlespacer").show();
			jQuery("#catButton").css("background-image","url(images/catunten.png)");
		}
		else {
			jQuery('#offon').val(0);
			jQuery("#categoriesmenu").show("fast");
			jQuery(".littlespacer").hide();
			jQuery("#catButton").css("background-image","url(images/catoben.png)");
		}
		
		 });

// Lang Scheisse

langbutton = "off";

jQuery(".luca").click(function(){
	id = this.id;
	jQuery("#curr_flag").html("<img src='images/flags/"+ id+".png>")
});

jQuery("#language_button").click(function(){
	
	if (langbutton == "on") {
	jQuery("#lang_flags").hide("fast");
	langbutton = "off";
	jQuery("#language_button").css("background-image","url(images/lang_down.gif)");
	}
	else {
		jQuery("#lang_flags").show("fast");	
		langbutton = "on";
		jQuery("#language_button").css("background-image","url(images/lang_up.gif)");
	}
});

los0 = "0";
los = parseInt(los0);
counter = "1";
jQuery(".next1").click(function(){
	if (los!=counter) {
	los+=1;
	db_abfrage();
	}
});

jQuery(".prev1").click(function(){
	if (los!=0) {
		los-=1;
		db_abfrage();
	}
	
	
});

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( jQuery(window).height() - this.height() ) / 2+jQuery(window).scrollTop() + "px");
    this.css("left", ( jQuery(window).width() - this.width() ) / 2+jQuery(window).scrollLeft() + "px");
    return this;
}


// Advent

jQuery("#adventLink").click(function(){
	jQuery("#overlay").show();
	jQuery("#adventInnen").fadeIn("fast");
	jQuery("#adventInnen").center();
});

jQuery("#adventClose, #overlay").click(function(){
	jQuery("#overlay, ,#adventInnen").fadeOut("fast");
});


jQuery(".doors").live("click", function(){
	id = this.id;
	jQuery('#calendar').load('show.php?i='+id+'');
});

jQuery("#adVback").live("click", function(){
	jQuery('#calendar').load('advent.php');
});

jQuery("#winnow").live("click", function(){
	var ajaxOpts = {  
			type: "post",  
			url: "win.php",
			data: "&name=" + jQuery(".advName").val(),
			success: function(data) {  
	
	jQuery(".okay").show();
	}  
	};  
	 
	jQuery.ajax(ajaxOpts);
});

//Db-Abfrage
function db_abfrage(){	
	var code = "";
	var code2 = "";
	jQuery.ajax({  
			type: "POST",  
         	 url: "news2.php",  
        	 data: " los="+ los +"", 
        	 success:
		
	
	function(theXML){
		jQuery('app',theXML).each(function(i){
			 
			var news = jQuery(this).find("news").text();
			var name = jQuery(this).find("head").text();
			counter = jQuery(this).find("counter").text();

			code += '<h1> '+name +' </h1> <p> '+ news+'</p> '
			
			
		});
		
		

	jQuery("#newshome").html(code);
	
}
	});		
	
}

//END Db-Abfrage

// COMMENT FUNCTION

//add click handler for button  
jQuery("#add").click(function() { 
	
	if(jQuery("#leaveComment").find("#comment").val() !="") {


	
	jQuery(".loader").show();
	//define ajax config object  
	var ajaxOpts = {  
	type: "post",  
	url: "addcomment.php",  
	data: "&name=" + jQuery("#leaveComment").find("#commentname").val() + "&comment=" + jQuery("#leaveComment").find("#comment").val() + "&appid=" + jQuery("#leaveComment").find("#comment_aid").val(),  
	success: function(data) {  
	
	jQuery(".loader").hide();	
		
	//create a container for the new comment  
	var div = jQuery("<div>").addClass("comment").prependTo(".comments");  
	//add author name and comment to container  
	jQuery("<b>").text(jQuery("#leaveComment").find("#commentname").val()).appendTo(div);  
	jQuery("<div>").text(jQuery("#leaveComment").find("#comment").val()).appendTo(div); 
	jQuery("#leaveComment").find("#comment").val(""); 
	}  
	};  
	 
	jQuery.ajax(ajaxOpts);
	
	
	
	if (jQuery(".comments").find("#noCommentyet").length > 0) {
		jQuery(".comments").find("#noCommentyet").remove();
	}
	
	
	
	}
	else {
	jQuery("#comment").css("border","1px solid #ff0000");
	}
	});  

// END COMMENT FUNCTION

}); //ENDE
