document.write('<style type="text/css">\
					.gallery_image img, .portfolio_image img { display:none; }\
				</style>');

jQuery(document).ready(function($) {
	
	
	$(".ban-news").hover(function() {
		$(this).fadeTo("fast",0.4);
	},function() {
		$(this).fadeTo("fast",1.0);
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'facebook'}) /* light_rounded / dark_rounded / light_square / dark_square / facebook */
							  .children('img').hover(function() {
										$(this).fadeTo('normal',0.3);
									},function() {
										$(this).fadeTo('normal',1.0);
									});
		
	$(".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;
		}
		
	});
	
	$("#menu a").removeAttr('title');
	
	$("#menu ul:first > li > a, .flickr_badge_image").hover(function() {
					$(this).stop(true,true);
					$(this).animate({top: '-4px'});
				},function() {
					$(this).animate({top: '0px'});
				});
	$("#menu ul:first ul li:first-child").css({paddingTop: '7px'});
	$("#menu ul:first ul li:last-child").css({paddingBottom: '5px'});
	$("#menu li").hover(function() {
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn('normal');
	},function(){
		$(this).find('ul:first').css({display: 'none',visibility: 'hidden'});
	});
	
	$(".box-close").click(function() {
		$(this).parents(".box").slideUp("fast");
	});
	
	$( ".nitrografix-tabs" ).tabs({ fx:  { height: "toggle", duration: "normal" } });
	$(".nitrografix-accordion" ).accordion({ autoHeight: false });
	
	$('.nitrografix-slideshow').nivoSlider({controlNav: false});
	
	$('.divider a').click(function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	// 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');
					var title = $object.attr('title');
					if( alt != undefined ) $this.attr('alt',alt);
					if( title != undefined ) $this.attr('title',title);
					$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('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'));
			}
    	}
    });	
	

	
});
