/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



var GALLERY = {
  container: '#photos_container',
  url: 'php/thumbs.php',
  delay: 2000,
  attemps: 1,
  reset: function() {
      this.delay = 2000;
      this.attemps=2;
  },

   

  load: function(album) {
    var _gallery = this;
	  $.ajax({ 
      type:"get", 
      url: this.url,
      data:  "album=" + album, 
      
      
      beforeSend: function(){
           // $('#photos_container').empty();
            $('#page_preloader').fadeIn();
//            $('#photos_container').append('<div id="gal_preloader"><img src="icons/preload.gif"></div>');
//            $('#gal_preloader').addClass('preloader');
    
    
  }, 
  
        error: function(xhr, status){
            if(_gallery.attemps--== 0) {
             _gallery.reset();
             $('#page_preloader').fadeOut(function(){
                 $('#ajax_err_msg').fadeIn();});
             
             return;
            }
            setTimeout(function(){_gallery.load();}, _gallery.delay *=2);
            },
        
        
  
      success: function(data){ 
        //alert (data);
		_gallery.reset();
                var images = $.parseJSON(data);
//		$('#photos_container').empty();
                
                //alert (images.length);
   if (images.length > 0 ){
   $.each(images, function() {  
         
		 
		  _gallery.display(this);
        });
   }
   
   if (images.length == 0 ){ $('#photos_container').append('<div id="no_img_msg">В этом альбоме нет ни одной фотографии.</div>');}
         // $.each(images, function() {  
          //alert (images.Object.src[1]);
        //});*/
//          
//   } 
//},
//
//complete: function() {
      $('#page_preloader').fadeOut();
      $('#links_container ul').fadeOut('slow', function(){
           
            $('#links_container').scrollTo('#photos_container', 'slow');
         $('#photos_container').animate({opacity: '1'}, 'slow')
     });
//        alert ('Complete!')
                    $('page_preloader').fadeOut();
        
      		    $('#photos_container').append('<div id="back_link" ><a href="#" id="back_to_albums" class="back_to_albums" style="background: #777 url(icons/arrow-up.png) no-repeat center center"><div></div></a></div> ', function(){
                        
                
			$('#back_to_albums').addClass('back_to_albums');
                        $('#back_to_albums').animate({opacity: '1'}, 'slow');
                        
                    });        
                        $('#photos_container a div').fadeTo('fast', '0.7');
                        
                           var p_c_height = $('#photos_container').height();
                        
                        if (p_c_height > 650){
                            $('#links_container').animate({"height": p_c_height+50}, 'slow');
                        }
                        
         $('a[rel="prettyPhoto[pp_gal]"]').prettyPhoto({
             
			animation_speed: 'normal', /* fast/slow/normal */
			slideshow: 5000, /* false OR interval time in ms */
			autoplay_slideshow: false, /* true/false */
			opacity: 0.8, /* Value between 0 and 1 */
			show_title: true, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			default_width: 500,
			default_height: 344,
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			horizontal_padding: 20, /* The padding on each side of the picture */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			wmode: 'opaque', /* Set the flash wmode attribute */
			autoplay: true, /* Automatically start videos: True/False */
			modal: false, /* If set to true, only the close button will close the window */
			deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
			overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
			keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
			changepicturecallback: function(){_uacct = "UA-149509-2"; urchinTracker();}, /* Called everytime an item is shown/changed */
			callback: function(){}, /* Called when prettyPhoto is closed */
			ie6_fallback: true,
			
                        markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
											<a class="pp_next" href="#">next</a> \
											<a class="pp_previous" href="#">previous</a> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<div class="pp_nav"> \
												<a href="#" class="pp_arrow_previous">Previous</a> \
												<p class="currentTextHolder">0/0</p> \
												<a href="#" class="pp_arrow_next">Next</a> \
											</div> \
											<p class="pp_description"></p> \
											{pp_social} \
											<a class="pp_close" href="#">Close</a> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '<div class="pp_gallery"> \
								<a href="#" class="pp_arrow_previous">Previous</a> \
								<div> \
									<ul> \
										{gallery} \
									</ul> \
								</div> \
								<a href="#" class="pp_arrow_next">Next</a> \
							</div>',
			image_markup: '<img id="fullResImage" src="{path}" />',
			flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
			quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
			inline_markup: '<div class="pp_inline">{content}</div>',
			custom_markup: '',
			social_tools: '<div class="pp_social"><div class="twitter"><a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div class="facebook"><iframe src="http://www.facebook.com/plugins/like.php?locale=en_US&href='+location.href+'&amp;layout=button_count&amp;show_faces=true&amp;width=500&amp;action=like&amp;font&amp;colorscheme=light&amp;height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:500px; height:23px;" allowTransparency="true"></iframe></div></div>' /* html or false to disable */
		});
     
     
  }
    
});
  },
  display: function(image_url) {
    
    
    
//	$('#photos_container').append('<a rel="my_gallery" href="' + image_url.image + '" ><img src="' + image_url.src + '"></img></a>');
        $('#photos_container').append('<a rel="prettyPhoto[pp_gal]" href="' + image_url.image + '" style="background: url(' + image_url.src + ') no-repeat center center"><div></div></a>');
	//alert (image_url);
	//$('<a href="' + image_url.image + '" target="_blank"><img src="' + image_url.src + '"></img></a>').hide().load(function() { $(this).fadeIn(); }).appendTo('#photos_container');
  }
  
};



