

jQuery(document).ready(function(){

$(window).load(function() {
	$('span#loading_gif').hide();
	$('#curtain').css({'display':'none'});

});


var image_width;

$("ul.feature_list li a img").lazyload({ 
									effect : "fadeIn",
									threshold : 200,
									container: $("ul.feature_list"),
									placeholder: "img/FD_placeholder.png"
		});

			// set the spacing for elements (know the width)
	
	    // know the width of the screen
            var screen_width = $(window).width();

        // define the width of each elements
            elem_width = image_width; //500;
            var visible_part_width = image_width/3; //50*2; // the width of the visible part of the picture (2 pictures)
            var elem_margin = ((screen_width-elem_width)-visible_part_width)/4;
        



		$('#the_page').hide();




		function image_resize(image_width) {
			
			if($('li.feature_container').length > 0) {

				image_height = 460; //$(document).height()*0.65;
				ratio = image_height/$('li.feature_container img').attr('height');
				image_width = 700; //$('li.feature_container img').attr('width')*ratio;

				$('li.feature_container img').css({'height':image_height+'px', 'width':image_width+'px'});
			}
			
			// set the spacing for elements (know the width)
	
	    // know the width of the screen
            var screen_width = $(window).width();

        // define the width of each elements
            elem_width = image_width; //500;
            var visible_part_width = image_width/3; //50*2; // the width of the visible part of the picture (2 pictures)
            var elem_margin = ((screen_width-elem_width)-visible_part_width)/4;
        
        
            $('li.feature_container').each( function() {
        
        
				var id = $(this).attr('id');
                            
				//  var elem_width = $('li.feature_container img').css('width');
				//                            var elem_width =    $($('li#'+id).find('img')[0]).width();
        
				elem_margin = ((screen_width-elem_width)-visible_part_width)/2;
				$(this).css({width:elem_width+'px', margin:'0px 0px 0px '+elem_margin+'px'})
            
            
            });
	

		
		// setup things and define click event / navigation
		var incr=0;
      var content_array = new Array();
        



	
	$('.issuu_content').each(function() {
		$(this).hide();
	});
	
	// callback function after the scroll from the menu
	function hide_picture_show_pdf(id) {

		$('.issuu_content').each(function() {
			$(this).hide();
//			$(this).siblings('a').show();

/* 			$(this).stop().animate({ opacity: 0.0 }, 500); */
			$(this).siblings('a').stop().animate({ opacity: 1.0 }, 500).show();			

		});



//		$(id).children('a').hide();
		$(id).children('span').show();

		$(id).children('a').stop().animate({ opacity: 0.0 }, 500).hide();
/*		$(id).children('span').siblings('a').stop().animate({ opacity: 1.0 }, 500);			
*/


	}

	$('.feature_container a').click(function() {
		
		
		
		var id = '#' + $(this).parent('li').attr('id');
		$.scrollTo(id, 1000, {axis:'x', offset: {left:-(screen_width/2-visible_part_width*1.5), top:'0'}, onAfter: hide_picture_show_pdf(id) });
		
	});


		$('#onlinefeatures_nav_menu li a').click(function() {

			var id = $(this).attr('href');
				offset = screen_width/2-visible_part_width*1.5;
		

		
			$.scrollTo(id, 1000, {axis:'x', offset: {left:-(screen_width/2-visible_part_width*1.5), top:'0'}}); //, onAfter: hide_picture_show_pdf(id)   
			return false;
		
		});



        
        $('li.feature_container').each( function() {
            var id = $(this).attr('id');
            
            
//            console.log(id);

            
            var img = $($('li#'+id).find('img')[0]).attr('src');
            
//            console.log(img);
            
            var page_content =  $('li#'+id).html();
            var img_object =    $($('li#'+id).find('img')[0]);
            
            // click event sur images

            $(img_object).unbind('click');
            
            $(img_object).bind('click', function(e) {


    
    			var id = $(this).parent('li').attr('id');
                $.scrollTo('#'+id, 1000, {axis:'x', offset: {left:-(screen_width/2-visible_part_width*1.5), top:'0'}});   
				$(this).hide();

// .SHOW ALL IMAGES INSIDE
/*
				$('ul.feature_list li').each( function(){ 
					$(this).children('img').show();
					
				});
*/
// THEN .HIDE THIS SPECIFIC ONE
				$(this).hide();
            });
            incr=incr+1;

        });
        
        total_width = (elem_width*(incr))+elem_margin*(incr+2);
			    $('ul.feature_list').css({width:total_width+"px"});


				if ($('feature0').length<0) {
					$('ul.feature_list').prepend('<li class="feature_container" id="feature0"></li>');
				}
				
				return (screen_width/2-visible_part_width*1.5);
			
		}
		
		initial_scroll = image_resize(image_width);
		$(window).wresize(image_resize);
		
				
		



	
		

// make HEADER AND TITLE fixed: no movements
		
		if($('h2.OnlineFeature').length>0) {
		
			// the page is using the Online Feature template
			header_top = 10;
			var header_height = $('#header').height();
			var header_marginb = $('#header').css('margin-bottom');
			var title_top = parseFloat(header_height)+parseFloat(header_marginb);

			$('#header').css({'position':'fixed', 'top':'10'});
			$('h2.OnlineFeature').css({'position':'fixed', 'top':title_top});
			
			// make the menu
			
			var buffer_link = "";
			
			$('ul.feature_list li p:last').each(function() {
				
				buffer_link = buffer_link + $(this).html() +"";

			});

//console.log(buffer_link);
			
		}
		
		

// transform navigation links into animated ScrollTo
/*
$('#menu_navigation a').click( function() {
            var id = $(this).attr('id');
            
                $.scrollTo('#'+id, 1000, {axis:'x', offset: {left:-(elem_margin*2+visible_part_width)/1.3, top:'0'}});                
                return false;

});

*/





		if ($('#onlinefeatures_nav_menu').length > 0) {
			
//			$('#header_banner img').hide();
$('#header_banner img').attr('src', 'http://sangbleu.com/wordpress/wp-content/themes/sangbleu.2/images/sangbleu_onlinefeats_title.jpg');
$('#header').css({'position':'fixed'});
$('#nav').css({'margin-left':'3px'});



			$('ul#nav li').each(function() {
				$(this).hide();
			});
			
			$('ul#nav').append(
				'<li class="page_item"><a href="http://sangbleu.com">SANGBLEU.COM</a></li>'
			);
			
			var myFile = document.location.toString();
			if (myFile.match('#')) { // the URL contains an anchor
				
				var myAnchor = '#' + myFile.split('#')[1];
				/* $('#header').append(myAnchor); */
/* 				console.log(myAnchor); */
/* 				console.log('hello'); */
				
/*    				$.scrollTo(myAnchor, 1000, {axis:'x', offset: {left:-(screen_width/2-visible_part_width*1.5), top:'0'}}); */


			} else {
			  // click the first navigation item
/* 			  $('ol#nav li:first').click(); */

//console.log('...');

			}
			
			

			
		}
		
		
		
		
		
		

// extend canvas size
	// multiply known width of elements by var.incr
	
	    		$('#the_page').show();

	
});



