$(window).load(function(){
$('body').addClass('ui-widget-content ui-corner-all');
$('#switcher').hide();
    $('.ui-widget-content').css('border','0');
    $('#lightboxes').css('visibility','visible');
	
$("#loaderIcon").spin({
lines: 12, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 10, // The radius of the inner circle
color: '#f60f60', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false // Whether to render a shadow

});setTimeout(function(){ $("#loaderIcon").spin(false); }, 2000);
	
	$('#stickyCP').show();		
	$('#stickyCP').css({marginLeft:-30});
	$('#stickyCP').delay(300).animate({marginLeft:1});
	
});


$(document).ready(function() {
$(window).scroll(function () {
		var a = $(window).scrollTop();
		if (a > 200) {
			$("#backtotop").fadeIn("slow");
		}
		if (a < 200) {
			$("#backtotop").fadeOut("slow");
		}
	});
	$("#backtotop").hover(function () {
		$(this).addClass("hover");
	},
	function () {
		$(this).removeClass("hover");
	});
	$(".meta div ").hover(function () {
		$(this).addClass("hover");
	},
	function () {
		$(this).removeClass("hover");
	});
	$("#backtotop").click(function () {
		$.scrollTo(0, {
			duration: 700,
			axis: "y"
		});
	});	
	


 $(function() {
		$("#backtotop")
		.mouseenter(function() {
			$(this).addClass('ui-state-hover');
		})
		.mouseleave(function() {
			$(this).removeClass("ui-state-hover");
		});	
	});


$('#stickyCP').sticklr({
			animate     : true,
            relativeTo  : 'center',
              relativeGap : 10,
				showOn	: 'click',
                stickTo: 'left'
			});

	
	$(function() { $.reject(); });
 $.reject({
                closeCookie: true // Set cookie to remmember close for this session
            }); 
			

$(function() {	
		$( "#dialog2" ).dialog({
			autoOpen: false,
			show: "fade",
			title: 'LightBoxes Help',
			width: 725,
			modal: true,
			position: 'top', 
			hide: "fade"
		});
		$( "#showHelp" ).click(function() {
			$( "#dialog2" ).dialog( "open" );
			return false;
		});});
			
		$(".sticklr li a:not(.gal, .themer, .sticklr-title a)").mouseenter(function(){
		$(this).addClass("ui-state-hover");
	});

	$(".sticklr li a:not(.gal, .themer, .sticklr-title a)").mouseleave(function(){
		$(this).removeClass("ui-state-hover");
	});	

$(function() {

		$( "#toggleicons_menu" ).click(function() {
			$('ul.icon').slideToggle('slow');
  			return false;
		});
		
	});
	
	
	
 // ======================= QTip Code ===============================
 
 
 $('.sticklr a[title]').qtip(
 { 
 show: {
                  solo: true
                },
 position: {
	  my: 'right center', 
      at: 'left center',
      viewport: $(window),
	  adjust: {
       method: 'flip none'
      }
   },
   style      : {
         widget: true,
		 classes: 'ui-tooltip-rounded'
      }
 }
 );
 
  $('#switcher_btn').qtip(
 { style      : {
         widget: true,
		 classes: 'ui-tooltip-rounded'
      }
 }
 );
  $('#options a[title]').qtip(
 { style      : {
         widget: true,
		 classes: 'ui-tooltip-rounded'
      }
 }
 );
  

 $('.description').live('click', function() {
   $(this).qtip({
      overwrite: false, 
     content   :{
			text: $('.description_holder', this),
            title: {
                text: 'Image Info',
                button: true
            }
			},
      show: {
	  effect: function(offset) {
         $(this).fadeIn(700); // "this" refers to the tooltip
      },
         event: 'click',
		  solo: true,
            modal: true,
			ready:true
        
      },
        hide: false,
   position   : { my: 'center',
            at: 'center',
            target: $(window)},
      style      : {
         widget: true,
		  classes: 'ui-tooltip-rounded'
      }
	  
   }); 
});	

	
$('.theme').themeswitcher();
$('ul.icon').show();


 // ======================= Isotope ===============================


var $container = $('#lightboxes');

$(function(){

      $container.imagesLoaded( function(){
        $(this).isotope({
          itemSelector : '.item',
		    masonry : {
   columnWidth :  $container.width() / 4 }
        });
      });   
	   $('input#discussion-search').quicksearch('#lightboxes .item', {
	   'loader': 'span.loading',
        'show': function() {
            $(this).addClass('quicksearch-match');
        },
        'hide': function() {
            $(this).removeClass('quicksearch-match');
        }
    }).live('keyup',function(){
        setTimeout( function() {
            $container.isotope({ filter: '.quicksearch-match' });
			 $container.isotope();  
        
        }, 100 );
    });
	  
	  
	  
    });
	
	
  // ======================= Infinite Scroll  ===============================

  $container.infinitescroll({
    navSelector  : 'a#nav',    // selector for the paged navigation 
    nextSelector : 'a#nav',  // selector for the NEXT link (to page 2)
    itemSelector : '.item',     // selector for all items you'll retrieve
	loading: {
finishedMsg: 'No more Images to load.',
img: 'res/icons/load.gif',
msgText: "<em>Loading Images...</em>"
},
behavior : 'twitter',
    errorCallback: function() { 
      // fade out the error message after 2 seconds
      $('#infscr-loading').animate({opacity: 0.8},2000).fadeOut('normal');   
    }
    },
    // call Isotope as a callback
    function( newElements ) {
      $container.isotope( 'insert', $( newElements ) );
 
 $container.isotope({ filter: '*' });  
	 $('input#discussion-search').quicksearch('#lightboxes .item', {
	  'loader': 'span.loading',
        'show': function() {
            $(this).addClass('quicksearch-match');
        },
        'hide': function() {
            $(this).removeClass('quicksearch-match');
        }
    }).live('keyup',function(){
        setTimeout( function() {
            $container.isotope({ filter: '.quicksearch-match' });
			 $container.isotope();  
        
        }, 100 );
    });

		$('ul.icon').show();
	  $("a[rel^='prettyPhoto']").prettyPhoto(); 
 
 			
 $('.tooltip-sticky').hide();

    }
  );
  


 $('a#infiniteScroll').click(function(e){
    // call this whenever you want to retrieve the next page of content
    // likely this would go in a click handler of some sort
    e.preventDefault();
        $container.infinitescroll('retrieve');
	$('a#nav').hide();
    return false;
  });
  
  
 // ======================= End of Isotope/Infinite Scroll Code ===============================
	
	 // ======================= Filter and Sort Code ===============================   
   
	 // filter buttons
    $('.filters a').click(function() {
        var selector = $(this).attr('data-filter');
        $container.isotope({
            filter: selector
        });
      $container.isotope('reLayout');  
        return false;
    });
	

      // sorting
	
	 $('.sorting a.list').click(function(){
        // get href attribute, minus the #
        var $this = $(this),
            sortName = $this.attr('href').slice(1),
            asc = $this.parents('.sort').hasClass('asc');
        $container.isotope({ 
          sortBy : sortName,
          sortAscending : asc
        });
        return false;
      });
	
	var $sortBy = $('#sort-by');
    $('#shuffle a').click(function(){
      $container.isotope('shuffle');
      $sortBy.find('.selected').removeClass('selected');
      $sortBy.find('[data-option-value="random"]').addClass('selected');
      return false;
    });
       
    $(function(){
      $container.isotope({
        itemSelector : '.item',
        getSortData : {
          category : function( $elem ) {
            return $elem.attr('data-category');
          },
          number : function( $elem ) {
            return parseInt( $elem.find('.number').text(), 10 );
          },
          date : function( $elem ) {
            return parseFloat( $elem.find('.date').text().replace( /[\(\)]/g, '') );
			
          },
          folder : function( $elem ) {
            return $elem.find('.folder').text();
          },
		   name : function ( $elem ) {
            return $elem.find('.sorttitle').text();
          },
		   imageWidth : function ( $elem ) {
            return $elem.find('.width').text();
          },
		   imageHeight : function ( $elem ) {
            return $elem.find('.height').text();
          },
		  width : function ( $elem ) {
            return $elem.find('a img').width();
          },
		   height : function ( $elem ) {
            return $elem.find('a img').height();
          }
		 
        }
      });      
    });
	

$(function(){
		//all hover and click logic for buttons
		$(".fg-button:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.fg-buttonset-single:first').find(".fg-button.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active.fg-button-toggleable, .fg-buttonset-multi .ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.fg-button-toggleable, .fg-buttonset-single .fg-button,  .fg-buttonset-multi .fg-button') ){
				$(this).removeClass("ui-state-active");
			}
		});
	});
	
	$(function(){
		//all hover and click logic for buttons
		$(".list:not(.ui-state-disabled)")
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		)
		.mousedown(function(){
				$(this).parents('.sort:first, .filters:first').find(".list.ui-state-active").removeClass("ui-state-active");
				if( $(this).is('.ui-state-active') ){ $(this).removeClass("ui-state-active"); }
				else { $(this).addClass("ui-state-active"); }	
		})
		.mouseup(function(){
			if(! $(this).is('.ui-state-active.list') ){
				$(this).removeClass("ui-state-active");
			}
		});
	});
	
	
 // ======================= Control Panel  ===============================

 $(function(){

//Home Button

//Info Button		
        $( "#information2" ).button({
          label: "Show Help",
            icons: {
                primary: "ui-icon-help"
            }
			 }).click(function() {
			var options;
			if ( $( this ).text() === "Show Help" ) {
				options = {
					label: "Hide Help",
					icons: {
						primary: "ui-icon-help"
					}
				};$( "#dialog" ).dialog( "open" );
			} else {
				options = {
					label: "Show Help",
					icons: {
						primary: "ui-icon-help"
					}
				};$( "#dialog" ).dialog( "close" );
			}
			$( this ).button( "option", options );
        });
//EXIF Button		
		$( "#exif_info" ).button({
  label: "EXIF",
            icons: {
                primary: "ui-icon-newwin"
            }
        });
	
//Cart Button		
		$( "#show_cart" ).button({
  label: "Show Cart",
            icons: {
                primary: "ui-icon-cart",
				secondary: 'ui-icon-plus'
            }
        }).click(function() {
			var options;
			if ( $( this ).text() === "Show Cart" ) {
				options = {
					label: "Hide Cart",
					icons: {
						primary: "ui-icon-cart",
						secondary: 'ui-icon-minus'
					}
				};$( "#cart" ).dialog( "open" );
			} else {
				options = {
					label: "Show Cart",
					icons: {
						primary: "ui-icon-cart",
						secondary: 'ui-icon-plus'
					}
				};$( "#cart" ).dialog( "close" );
			}
			$( this ).button( "option", options );
		});
			
//Add to Cart Button		
		$(".add_cart").button({
  label: "Add to Cart",
            icons: {
                primary: "ui-icon-cart"
            }
        });	
//Favorites Button		
		
		
		$( "#favorites" ).button({
     label: "Fav",
            icons: {
                primary: "ui-icon-heart"
            }
        });
		
//Switcher Button
		$( "#switcher_btn" ).button({text: false,
            icons: {
                primary: "ui-icon-gear"
            }
           
			});

 $(function() {
		$(".icon li")
		.mouseenter(function() {
			$(this).addClass('ui-state-hover');
		})
		.mouseleave(function() {
			$(this).removeClass("ui-state-hover");
		});	
		
		$(".sticklr ul li a:not(.gal a,  .themer a .sticklr-title a)")
		.mouseenter(function() {
			$(this).addClass('ui-state-hover');
		})
		.mouseleave(function() {
			$(this).removeClass("ui-state-hover");
		});	
	});
	
	});

	
//Show-Hide Favorites Icons

$("#toggleIcons").click(function() {
$('ul.icon').slideToggle('slow');
  return false;
});

//Toggle Heart and Checkbox icons
$(".fav").live('click', function() {
  $(this).toggleClass('sticky')
  .removeClass('ui-icon-heart')
  .addClass('ui-icon-check')
    .toggleClass('fav')
    .closest('.item')
    .toggleClass('favorites');
});
$(".sticky").live('click', function() {
  $(this).toggleClass('fav')
  .removeClass('ui-icon-check')
  .addClass('ui-icon-heart')
    .toggleClass('sticky')
    .closest('.item')
    .toggleClass('favorites');
});


//Filter-Sort Menu											
//EXIF popup Tooltip
$('.cart_button').hide();
$('.tooltip-sticky').hide();
$('.printImage').hide();


//Gallery Size Slider
		
			$("#slider").slider({
				step: 130,
				range: "min",
				max: 1200,
				min: 460,
				stop: function(event, ui) { $('#lightboxes').isotope( 'reLayout');},
				slide: function(event, ui) {
					$('#lightboxes').css('width',ui.value+"px");
					$( "#amount" ).val( ui.value+"px" );
				}
			});
			$( "#amount" ).val( $( "#slider" ).slider( "value" ) );
			$("#lightboxes").each(function() {
				var width = $(this).width();
				$(this).css("width",width);
			});
			

//Control Panel Hide Button Function
var opened=true;
$(function(){
//fix the IE6 position fixed issue
if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
	$("#styleSwitcher").css("position", "absolute");
	$(window).scroll(function() {
		$("#styleSwitcher").css("top", $(window).scrollTop() + "px");
	});
}
});

	$('#switcher_btn').click(function(){
		if(opened){
			$('#styleSwitcher').animate({marginLeft:-204});
			$('#switcher_btn').addClass('ui-icon-closethick');
			$('#switcher_btn').animate({marginRight:0});
			opened=false;
		}else{
			$('#styleSwitcher').animate({marginLeft:25});
			$('#switcher_btn').animate({marginRight:20});
			opened=true;
		}
	});
	
	
	
	
	$('#switcher_btn').mouseover(function(){
		$(this).css({cursor:'pointer'});	
	});



 // ======================= LightBox ===============================
 
 
		
	
	
	




 // ======================= AddThis Code ===============================			
var addthis_config =
{
  ui_cobrand: 'Jalbum LightBoxes Skin'
};

});

