var $ = jQuery.noConflict();

var slides = 0;
var slide = 1;
var lastslide = 1;
	
$(document).ready(function() {
	
	//thumbnails show info
	$(".thumbframe").hover( function(){ $(this).find('div.infos').fadeIn(100); }, function(){ $(this).find('div.infos').fadeOut(100);});
	//remove the title from the alt
	$(".thumbframe").parent('a').each( function (){ $(this).removeAttr('title'); } );
	$(".thumbframe").parent('a').each( function (){ 
		$(this).attr('href', $(this).attr('href').split('?')[0] );		 
	} );
	
	//filter dropdown
	$('li.filter').hover(
			function() { $('ul', this).css('display', 'block'); },
			function() { $('ul', this).css('display', 'none'); });
						   
	// some goodness for the textfields (contact form)
	// store inition values
	var initName = $('#posName').val();
	var initEmail = $('#posEmail').val();
	var initRegard = $('#posRegard').val();

		$('#posName').bind('focus', 
					   function () { if( $(this).val() == initName ){ $(this).val(''); } }
			    ).bind('blur', function () { if( $(this).val() == '' || $(this).val() == ' ' ){ $(this).val(initName); } });
		$('#posEmail').bind('focus', 
					   function () { if( $(this).val() == initEmail ){ $(this).val(''); } }
			    ).bind('blur', function () { if( $(this).val() == '' || $(this).val() == ' ' ){ $(this).val(initEmail); } });
		$('#posRegard').bind('focus', 
					   function () { if( $(this).val() == initRegard ){ $(this).val(''); } }
			    ).bind('blur', function () { if( $(this).val() == '' || $(this).val() == ' ' ){ $(this).val(initRegard); } });
			
	//hyph
		
	//columnize tripple-columns
	$("#three-columns div").columnize({ columns: 3, lastNeverTallest: true }); //optional width: 900 + height: ??? setzen damit die vollaufen!
	$("#two-columns div").columnize({ columns: 2, lastNeverTallest: true }); //optional width: 900 + height: ??? setzen damit die vollaufen!
		
	//number of slides
	slides = $('#canvas img').length;
	
	//remove the hrefs - add js links for the slides + hide them
	$("a#prev-slide").attr('href', 'javascript:prevSlide();').css('display', 'none');
	$("a#next-slide").attr('href', 'javascript:nextSlide();').css('display', 'none');
	
	//hide all images
	$("#canvas img").css('display', 'none');
	
	//call the first slide
	switchSlide(1);

});

function switchSlide(theslide){
	//check buttons next / prev
	if(slide>1){
		$("a#prev-slide").attr('title', (slide-1)+' / '+slides);
		$("a#prev-slide").fadeIn('100');
	}
	else{
		$("a#prev-slide").fadeOut('100');
	}
	if(slide<slides){
		$("a#next-slide").attr('title', (slide+1)+' / '+slides);
		$("a#next-slide").fadeIn('100');
	}
	else{
		$("a#next-slide").fadeOut('100');	
	}	
	//remove the last slide	
	$("#canvas img").css('display', 'none');
	
	//read the subheadings + split into array
	var subhead = $("#canvas img:nth-child(" + theslide + ")").attr('alt').split(" / ");

	//fade out subheads
	$("#info").css('display', 'none');

	//change the subheadings
	$("#sub1").text(subhead[0])
	$("#sub2").text(subhead[1])
	
	//show the selected
	$("#canvas img:nth-child(" + theslide + ")").fadeIn('100');
	
	//fade in subheads
	$("#info").fadeIn('200');
		
};

function prevSlide(){
	lastslide = slide;
	
	if(slide > 1)
		slide--;	
		
	switchSlide(slide);
};

function nextSlide(){
	lastslide = slide;
	
	if(slide < slides)
		slide++;
		
	switchSlide(slide);
};