document.write('<style type="text/css">\
					.service_thumb img, .post-view img, .post-thumb img, .featured_work img, .portfolio_image img, .gallery_thumb img { display:none; }\
					.highlight-content { visibility: hidden, opacity: 0 }\
					#preload_highlight { display: block }\
				</style>');
				
jQuery(document).ready(function($) {

	if( typeof(Cufon) != 'undefined' ) {
		Cufon.set('fontFamily', 'Days');
		Cufon.replace('.head-name h2',{textShadow: '1px 1px rgba(0, 0, 0, 0.5)'});
	}

	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'}); // light_rounded / dark_rounded / light_square / dark_square / facebook 
	
	$(".widget_contactformwidget form").submit(function() {
	
		var hasError = false;
		$(this).find('.required').each(function() {
			$(this).removeClass('error');
			if($.trim($(this).val()) == '' ) {
				$(this).addClass('error');
				hasError = true;
			}
		});
		if( hasError == true ) {
			return false;
		}
		
	});
	
	

	
	$('.portfolio-slider').nivoSlider({effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
										slices:15,
										animSpeed:500, //Slide transition speed
										pauseTime:3000,
										startSlide:0, //Set starting Slide (0 index)
										directionNav: false, //Next & Prev
										directionNavHide:true,
										controlNav:true,
										keyboardNav:true,
										manualAdvance: false,
										captionOpacity: 0
										});
	
	// image loader
	$(this).delay(500,function() {
		
		// grab the images
		var $images = $('.preload_image img, .service_thumb img');
		
		// image length
		var max = $images.length;
		
		// loading div object
		var $loadDiv = null;
		
		// start loading
		if( max > 0 ) 
			LoadImage(0,max);
 
		function LoadImage(index,max) {
	
			if( index < max ) {
				
				var type = null; // or url
	 
				// new image object
				var img = new Image();
				
				// current image
				var $object = $images.eq(index);
				
				var $curr = $object.parent('div');
				if( $curr.size() == 0 ) {
					type = 'url';
					$curr = $object.parent().parent('div');
				}
				
				// load current image
				$(img).load(function () {
				
					$this = $(this);
					
					var width = $object.attr('width');
					var height = $object.attr('height');
					if( width && height ) $this.attr({width: width, height: height});
					var alt = $object.attr('alt');
					if( alt != undefined ) $this.attr('alt',alt);
					$object.remove();
					
					// hide it first + .hide() failed in safari
					$this.css('display','none');
					
					// remove loading class from div and insert the image into it
					
					( type == 'url' ) ? $curr.children('a').append(this) : $curr.append(this);
					
					// fade it in
					$this.addClass('image-roll')
						 .fadeIn(250,function() {
						
							$curr.css('background-image','none');
							
							if( type == 'url' ) {
							
								var $image = $curr.children('a').children('img');
								
								if( $curr.hasClass('gallery-image') ) {
									
									$curr.prepend($image);
									$curr.children('a').addClass('gallery-view-image')
													   .css('opacity',0)
													   .html('<img alt="' + alt + '" style="display: none" />');
									var link = $curr.parent().parent().children('h4').children('a').attr('href');
									$curr.append('<a href="kontakt.html" class="gallery-read-more" style="opacity: 0"></a>');
									$curr.children('.gallery-read-more').css('opacity',0); // IE BUG
								
									$(this).parent().parent().hover(function() {
										$this = $(this).children('div.gallery-image');
										$img = $this.children('img');
										$a = $this.find('a');
										$a.stop(true,true);
										$img.stop(true,true);
										
										$img.fadeTo('slow',0.3)
										$a.eq(0).animate({opacity: 1,left: '32px',filter: ''});
										$a.eq(1).animate({opacity: 1,right: '32px',filter: ''});
									},function() {
										$(this).children('div.gallery-image').children('img').fadeTo('slow',1.0)
										var $a = $(this).children('div.gallery-image').find('a');
										$a.eq(0).animate({opacity: 0,left: '16px',filter: 'alpha(opacity=0)'});
										$a.eq(1).animate({opacity: 0,right: '16px',filter: 'alpha(opacity=0)'});
									});
								}
								else {
									if( $curr.hasClass('more-view') ) $curr.prepend('<span class="fleche-more" style="width:'+$image.css('width')+';height:'+$image.css('height')+'"></span>');
									else if( $curr.hasClass('more-view-mini') ) $curr.prepend('<span class="fleche-more-mini" style="width:'+$image.css('width')+';height:'+$image.css('height')+'"></span>');
									else $curr.prepend('<span class="magnifying-glass" style="width:'+$image.css('width')+';height:'+$image.css('height')+'"></span>');
									
									$(this).hover(function() {
										$(this).stop(true,true);
										$(this).fadeTo("normal",0.3);
									},function() {
										$(this).fadeTo("normal",1.0);
									});
								}
							}
						
							if(index == (max-1)) {
								// remove loading div after all images loaded
								//$($loadDiv).remove();
							}
							else{
							  LoadImage(index+1,max);
							}
					});
					//$this.trigger('load');
				})
				.error(function () {
					$curr.remove();
					LoadImage(index+1,max);
				})
				.attr('src', $images.eq(index).attr('src'));
			}
    	}
    });	
	
	
	$('.nitrografix-slideshow').nivoSlider({controlNav: false});
	

	
	$('.divider a').click(function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});

	
	
	$(".current_page_ancestor:first").addClass('current_page_root');
	

	
	
	
});
