// bioterapeuta.com.pl

FADE = {
	AllImages 	: 12, 
	CurrentImage	: 1,	
	Delay 		: 11000,	
	FadeTime	: 3000,

	Go : function () {
				this.CurrentImage ++;
				
				if (this.CurrentImage > this.AllImages){
					this.CurrentImage = 1;
				}	
				this.Load(this.CurrentImage);
				
				setTimeout(function () { 
					FADE.Show(FADE.CurrentImage);
				}, this.Delay);
	},
	
	Show : function (current){
				var image_container_id =  (((current % 2) + 2) % 2);
		
				jQuery($('div#rotating_img_' + image_container_id).css({
					background: 'url(' + $('img#image_' + current).attr('src') + ')'
				}));
				
				switch (image_container_id){
					case 1:
						$('#rotating_img_1').fadeIn(this.FadeTime);
						break;
					case 0:
						$('#rotating_img_1').fadeOut(this.FadeTime);
						break;
				}
				
				this.Go();
	},
	
	Load : function (current){
		if (!($('#image_' + current).is())){
			$('<IMG id="image_' + current + '" src="images/menu_' + current + '.jpg ">').appendTo("#images_container");
		}		
	}
}



MENU = {
	id 		: 1,
	language 	: 'pl', 

	PrepareMenu : function (){

			$(".menuarea > div").each(function () {

				this.onmouseover	= function ()		{ MENU.setActive(this) 	};
				this.onmouseout		= function ()		{ MENU.setInactive(this) };
				this.onclick			= function ()		{ MENU.setChoosen(this)	}
				
				$(this).addClass("menuitem");
				
				//
				// Set first choosen
				//
				var menu_element	= this.getAttribute("menu");
				var menu_name			= this.getAttribute("name");
								
				if ( menu_element == MENU.id ) { $(this).addClass("menuchoosen") }
				$("<div class='menuquote'>" + menu_name +  "</div>").appendTo($(this));
			});		
	},

	setChoosen : function(obj){
			var menu_element	= obj.getAttribute("menu");
			
			if ( menu_element == MENU.id ) { 
				return false; 
			} else {
				MENU.id = menu_element;
			}
			
			//
			// remove old choosen / select new choosen
			//
			$(".menuarea > div").each(function () { 
				 $(this).removeClass("menuchoosen");		
			});	
			$(obj).addClass("menuchoosen");
			
			//
			// get content
			//
			PAGE.GetContent(MENU.id, MENU.language);
	},

	setActive	: function(obj)		{	$(obj).addClass("selected");	},
	setInactive	: function(obj)		{	$(obj).removeClass("selected");	}

}



PAGE = {
	GetContent : function( id, language ){
		MENU.language = language;
		$("#content").html($('#loading').html());
		$.ajax({
			url: "content_" + language + ".php",
			data: "id=" + id,
			cache: false,
			success: function(html){
				$("#content").html();
				$("#content").html(html);
				$('div#gallery a').lightBox();
			}
		});
	},
	
	
	ChangeMethod : function ( method ){
		$('span#methods p').each( function (){	$(this).hide();	});
		$('#' + method).show();
	},
	
	ChangePublication : function ( publication ){
		$('div#publications div').each( function (){ $(this).hide(); });
		$('#' + publication).show();
	},
	
	Tag : function(tag){
		$.ajax({
			url: "thanks.php",
			data: "tag=" + tag,
			cache: false,
			success: function(response){
				$("#thanks_list_content").html(response);
			}
		});		
	}
}

HEADER = {
	sloganId	: 0, 
	Delay		: 12000,
	bywords 	: [],
						
	ShowSlogan : function(id){
			$('#byword').fadeOut("fast", function(){
					$('#byword').html(HEADER.bywords[id]);
					$('#byword').fadeIn("fast");			
			});	
			this.sloganId ++;
			if ( this.sloganId >= this.bywords.length ){
				this.sloganId = 0;
			};
			
			setTimeout(function () {
				HEADER.ShowSlogan(HEADER.sloganId);
			}, HEADER.Delay);			
	},

	
	Initailize : function(){
			switch (MENU.language){
				case 'pl':	this.bywords = [
												'dyplomowany mistrz bioenergoterapii',
				   							'bioenergoterapia ziołolecznictwo czakroterapia',
				   							'medycyna naturalna',
				   							'wspomaganie leczenia wszelkich chorób',
												'leczenie niepłodności']
												break;
					
				case 'de':	this.bywords = [
												'der diplomierte Meister der Bioenergotherapie',
												'Bioenergotherapie Kräuterheilkunde Radiästhesie',
												'Auf seinem Konto hat er bereits 1000 Kinder'
												]
												break;

				case 'en':	this.bywords = [
												'Certified Master of the Bio-Energy Healing',
												'The Energy Healing, The Herbal Medicine, Dowsing',
												'He already has helped more than 1,000 children to come to this world'
												]
												break;
			}
			this.ShowSlogan(0);
	}

}



ADMIN = {
	Tag : function($tag){
		$('div#admin_tags_cloud a').each( function(){
			if (this.getAttribute('thanks_tag') == $tag){
				if ($(this).hasClass('tag_selected')){
					$(this).removeClass('tag_selected');
				}else{
					$(this).addClass('tag_selected');
				}
			}
		});
	},
	
	
	Save : function(){
		var tagsSelected = '';
		var tagsNew = '';
		var thanksYear = '';
		var description = '';
		var tags = '';
	
		$('div#admin_tags_cloud a').each( function(){
			if ($(this).hasClass('tag_selected')){
				tagsSelected += this.getAttribute('thanks_tag') + ',';
			}
		});
		thanksYear = $('#thanks_year').attr('value');
		tagsNew = $('#thanks_tags').attr('value');		
		description = $('#thanks_description').val();
		tags = tagsSelected + tagsNew;
		$.post("add_thanks.php", { action:"save",  tags:tags,  year:thanksYear,  desc:description }, function(data){ 
				$('div#admin_tags_cloud a').each( function(){
					$(this).removeClass('tag_selected');
				});
				$('#thanks_edit_cointainter').html(data);
				alert('Zapisane');
		});
	}
}

