/*******************************************************
+ FONT RESIZE
*******************************************************/
$(document).ready(function(){

		var theOriginalText = $('html');

		var originalFontSize = theOriginalText.css('fontSize');
		
		$('a#txt-reset').click(function()
		{
			  $('html').css('fontSize', originalFontSize);
	 		//theOriginalText.animate({fontSize: originalFontSize},600);
		});

	$('a.text-switcher').click(function() {
	
		var theText = $('html');
	
		var currFontSize = theText.css('fontSize');
		
		var finalNum = parseFloat(currFontSize, 10);
		
		var stringEnding = currFontSize.slice(-2);
		
		if(this.id == 'txt-smaller')
		{
			finalNum /= 1.2;
		}
		else if(this.id == 'txt-bigger')
		{
			finalNum *= 1.2;
		}
		
		theText.animate({fontSize: finalNum + stringEnding},600);
		 //$('html').css('fontSize', finalNum + stringEnding);
		
		// alert(currFontSize);
	
	
	});

});

/*******************************************************
+ HEADER SLIDESHOW
******************************************************/
//jQuery.noConflict();

$(document).ready(function(){
	// fading slider
	$('.fadeslider').kriesi_fade_slider({
			slides: '.featured',				// wich element inside the container should serve as slide
			animationSpeed: 1500,				// animation duration in milliseconds
			autorotation: true,					// autorotation true or false?
			autorotationSpeed:10,				// duration between autorotation switch in Seconds
			appendControlls: '#feature_wrap'	//element to append the controlls to
	});
	
	});
/*******************************************************
+ HEADER SLIDESHOW
******************************************************
$(document).ready(function(){	
	$("#slider").easySlider({
		auto: true, 
		continuous: true,
		controlsShow: false,
		speed: 1500,
		pause: 5000,
		numeric: false		
	});
});	
*/
/*******************************************************
+ HEADER SLIDESHOW
*******************************************************/
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	$(".mappress-container").hide(); //Show first tab content


	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$('.tab_content2').width(1);
		$('.tab_content2').height(1);
		$('.tab_content2').removeClass("tab_content");
		$(".tab_content").hide(); //Hide all tab content
		$('.mapp-canvas').width(1);
		$('.mapp-canvas').height(1);

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		if ( activeTab == '#avenue' ) {
			$('.tab_content2').width('625px');
			$('.tab_content2').height('100%');
			$('.mapp-canvas').width(620);
			$('.mapp-canvas').height(425);
			$('.tab_content2').addClass("tab_content");

		} else {
			$(activeTab).fadeIn(); //Fade in the active ID content
		}
		return false;
	});

});
/*******************************************************
+ STYLE SWITCH
*******************************************************/
jQuery.fn.styleSwitcher = function() {  

	$(this).click(function() {
	
		loadStyleSheet(this);
		
		return true;
	
	});
	
	function loadStyleSheet(obj) {
	
		$('body').append('<div id="overlay" />');
		
		$('body').css({height: '100%'});
		
		$('#overlay')
			.css({
			
				display: 'none',
				position: 'absolute',
				top:0,
				left:0,
				width: '100%',
				height: '100%',
				zIndex: 1000,
				background: "black url(http://www.domus-mea.de/wp-content/themes/domusmea/images/preloader.gif) no-repeat center"
			
			})
			
		.fadeIn(500, function() {
		
			$.get(obj.href+'&js',function(data){
			
				$('#stylesheet-link').attr('href', 'http://www.domus-mea.de/wp-content/themes/domusmea/css/' + data + '.css');
				
				cssDummy.check(function() {
				
					$('#overlay').fadeOut(500,function() {
						
					
					
						$(this).remove();
					
					});
				
				});
			
			});
		
		});
	
	}

	var cssDummy = {  
        init: function()
        {  
            $('<div id="dummy-element" style="display:none" />').appendTo('body');  
        },  
        check: function(callback) 
        {  
            if ($('#dummy-element').width()==2)  callback(); 
            else setTimeout(function(){cssDummy.check(callback)}, 200);  
        }  
    }  
    cssDummy.init(); 

}
$('#style-switcher a').styleSwitcher();




/*******************************************************
+ PRETTY PHOTO
*******************************************************/
$(document).ready(function()
{
	//$("a[rel^='prettyPhoto']").fadeOut();
	$("a[rel^='prettyPhoto']").prettyPhoto({// .gallery:first 
		animationSpeed:'slow',
		slideshow:2000, 
		autoplay_slideshow: false,
		alow_resize:true,
		theme: 'light_square' /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		});		
});

// -------------------------------------------------------------------------------------------
// The Image preloader
// -------------------------------------------------------------------------------------------


(function($)
{
	$.fn.kriesi_image_preloader = function(options) 
	{
		var defaults = 
		{
			repeatedCheck: 500,
			fadeInSpeed: 1000,
			delay:600,
			callback: ''
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var imageContainer = jQuery(this),
				images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}),
				imagesToLoad = images.length;				
				
				imageContainer.operations =
				{	
					preload: function()
					{	
						var stopPreloading = true;
						
						images.each(function(i, event)
						{	
							var image = $(this);
							
							
							if(event.complete == true)
							{	
								imageContainer.operations.showImage(image);
							}
							else
							{
								image.bind('error load',{currentImage: image}, imageContainer.operations.showImage);
							}
							
						});
						
						return this;
					},
					
					showImage: function(image)
					{	
						imagesToLoad --;
						if(image.data.currentImage != undefined) { image = image.data.currentImage;}
												
						if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
												 
						if(imagesToLoad == 0)
						{
							if(options.delay > 0)
							{
								images.each(function(i, event)
								{	
									var image = $(this);
									setTimeout(function()
									{	
										image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed);
									},
									options.delay*(i+1));
								});
								
								if(options.callback != '')
								{
									setTimeout(options.callback, options.delay*images.length);
								}
							}
							else if(options.callback != '')
							{
								(options.callback)();
							}
							
						}
						
					}

				};
				
				imageContainer.operations.preload();
		});
		
	}
})(jQuery);




// -------------------------------------------------------------------------------------------
// The Fade Slider
// -------------------------------------------------------------------------------------------

(function($)
{
	$.fn.kriesi_fade_slider= function(options) 
	{
		var defaults = 
		{
			slides: '>div',				// wich element inside the container should serve as slide
			animationSpeed: 900,		// animation duration
			autorotation: true,			// autorotation true or false?
			autorotationSpeed:3,		// duration between autorotation switch in Seconds
			appendControlls: '',
			backgroundOpacity:0.8		// opacity for background
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function()
		{
			var slideWrapper 	= $(this),								
				slides			= slideWrapper.find(options.slides).css({display:'none',zIndex:0}),
				slideCount 	= slides.length,
				currentSlideNumber = 0,
				interval,
				current_class = 'active_item',
				controlls = '',
				skipSwitch = true;
				
				slides.find('.feature_excerpt').css('opacity',options.backgroundOpacity);
				
				slideWrapper.methods = {
				
					init: function()
					{
						slides.filter(':eq(0)').css({zIndex:2, display:'block'});
						
						if(slideCount <= 1)
						{
							slideWrapper.kriesi_image_preloader({delay:200});
						}
						else
						{
							slideWrapper.kriesi_image_preloader({callback:slideWrapper.methods.preloadingDone, delay:200});
							
							if (options.appendControlls)
							{
								controlls = $('<div></div>').addClass('slidecontrolls').css({position:'absolute'}).appendTo(options.appendControlls);
								slides.each(function(i)
								{	
									var controller = $('<span class="ie6fix '+current_class+'"></span>').appendTo(controlls);
									controller.bind('click', {currentSlideNumber: i}, slideWrapper.methods.switchSlide);
									current_class = "";
								});	
							}
						}						
					},
					
					preloadingDone: function()
					{
						skipSwitch = false;
						
						if(options.autorotation)
						{
							slideWrapper.methods.autorotate();
						}
					},
					
					switchSlide: function(passed)
					{	
						var noAction = false;
						
						
						if(passed != undefined && !skipSwitch)
						{	
							if(currentSlideNumber != passed.data.currentSlideNumber)
							{	
								currentSlideNumber = passed.data.currentSlideNumber;
							}
							else
							{
								noAction = true;
							}
						}
						
						if(passed != undefined)
						{	
							clearInterval(interval);
						}
						
						if(!skipSwitch && noAction == false)
						{	
							skipSwitch = true;
							var currentSlide = slides.filter(':visible'),
								nextSlide = slides.filter(':eq('+currentSlideNumber+')');
								if(options.appendControlls)
								{	
									controlls.find('.active_item').removeClass('active_item');
									controlls.find('span:eq('+currentSlideNumber+')').addClass('active_item');									
								}
								
							currentSlide.css({zIndex:4});	
							nextSlide.css({zIndex:2, display:'block'});
							
							currentSlide.fadeOut(options.animationSpeed, function()
							{
								currentSlide.css({zIndex:0, display:"none"});
								skipSwitch = false;
							});
						}
					},
					
					autorotate: function()
					{	
						interval = setInterval(function()
						{ 	
							currentSlideNumber ++;
							if(currentSlideNumber == slideCount) currentSlideNumber = 0;
							
							slideWrapper.methods.switchSlide();
						},
						(parseInt(options.autorotationSpeed) * 1000));
					}
				
				};
				
				slideWrapper.methods.init();
		});
		
	}
})(jQuery);
