/* Author: SÜTTI it.design

*/


String.prototype.reverse = function(){
    splitext = this.split("");
    revertext = splitext.reverse();
    reversed = revertext.join("");
    return reversed;
}

if( navigator.userAgent.match(/Android/i) ||
	 navigator.userAgent.match(/webOS/i) ||
	 navigator.userAgent.match(/iPhone/i) ||
	 navigator.userAgent.match(/iPod/i)
	 ){
	 	var mobile = true;
	 }


$(document).ready(function(){
	
	
	
	$("select, :checkbox, :radio, :file").uniform();
	
	
	if(!Modernizr.input.placeholder) {
		$("input, textarea").each( function() {
			if($(this).val()=="" && $(this).attr("placeholder")!="") {
				$(this).val($(this).attr("placeholder"));
				$(this).focus( function() {
					if($(this).val()==$(this).attr("placeholder"))
						$(this).val("");
				});
				$(this).blur( function() {
					if($(this).val()=="")
						$(this).val($(this).attr("placeholder"));
				});
			}
		});
	}
	
	
	
	if(mobile){			
		$('html').addClass('mobile');		
	}	
	
	
	var slider = $('#slider').bxSlider({
		mode: 'horizontal',
		controls: false,
		auto: true,
		autoHover: true,
		pause: 5000,
		onBeforeSlide: function(currentSlideNumber, totalSlideQty, currentSlideHtmlObject){
			$('.slideItem').show();	
			$('#infolist li.active').removeClass('active');
			$('#infolist li').eq(currentSlideNumber).toggleClass('active');
		}		
	});
	$('#infolist li').hover(function(){			
		slider.stopShow();
		slider.goToSlide($(this).index());	
	},function(){
		slider.startShow();
	});
	
	$('#infolist li').click(function(e){
		e.preventDefault();
		//slider.stopShow();
		slider.goToSlide($(this).index());
		//slider.startShow();
	})
	
	//$('ul.collapsable').slideUp();
	$('a.col').click(function(e){
		e.preventDefault();		
		$(this).parent().find('ul.collapsable').slideToggle();
	});

	
	/*----------
	 	TABS
	 ----------*/
	//When page loads...	
	$(".tab_content").hide(); //Hide all content
	if(Modernizr.localstorage){
		var activeTab = localStorage.getItem('helferliste-activeTab');
	}
	if(activeTab && $('#listTab'+activeTab).length == 1){
		$('#listTab'+activeTab).addClass("active").show();
		$('#tab'+activeTab).show();
	}else{
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //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_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		if(Modernizr.localstorage){
			localStorage.setItem('helferliste-activeTab', $(this).attr('data-id'));
		}
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

	$('#thumb-button').click(function(e){
		e.preventDefault();
		if(!$.supersized.vars.is_paused && $('#supersized').css('display') == 'block'){
			$.supersized.vars.is_paused = false;
			api.playToggle();			
			stopSlideShow();
		}else{
			$.supersized.vars.is_paused = true;
			if( $('#supersized').css('display') == 'none'){				
				api.playToggle();					
			}else{
				if($.supersized.vars.is_paused){
					stopSlideShow();
				}else{
					startSlideShow();
				}				
			}						
		}				
	});
	
	$('#pic_wrapper img').click(function(){
		api.goTo($(this).index() + 1);
		startSlideShow();
	});
	
	
	$('#supersized').live('play', function(){
		startSlideShow();
	});
	
	
	
	
	$('a.galerie').click(function(){
		$.blockUI({ 
		 	message: '<h1>Bilder werden geladen <img src="assets/template/img/icons/loading.gif" alt="" /></h1>' 
		 });  
	});
	
});


 
function stopSlideShow(){
	$('#supersized, #prevslide, #nextslide, #progress-back, #thumb-tray, #tray-button, #prevthumb, #nextthumb').fadeOut();
	$('body,html').css('overflow','auto');
}

function startSlideShow(){
	$('#supersized, #prevslide, #nextslide, #progress-back, #thumb-tray, #tray-button, #prevthumb, #nextthumb').fadeIn();
	$('body,html').css('overflow','hidden');	
}

function placeholder() {
	if(!Modernizr.input.placeholder) {
		$("input, textarea").each( function() {
			if($(this).val()=="" && $(this).attr("placeholder")!="") {
				$(this).val($(this).attr("placeholder"));
				$(this).focus( function() {
					if($(this).val()==$(this).attr("placeholder"))
						$(this).val("");
				});
				$(this).blur( function() {
					if($(this).val()=="")
						$(this).val($(this).attr("placeholder"));
				});
			}
		});
	}
}








