// function callback on showing image
function superbgimage_show(img) {
	jQuery('#superbgimage').css('background', 'none');
	jQuery('#image_name').html(jQuery('#pagination a' + "[rel='" + img + "']").attr('title'));
	jQuery('#image_name, #set_name, #add_to_lightbox').fadeIn('slow');
}

// function callback on hiding image
function superbgimage_hide(img) {
	jQuery('#image_name, #set_name, #add_to_lightbox').hide();
}

var isOpen=false;

(function(jQuery) {
	
	// Stills Rollover
	jQuery('.still').live('mouseenter', function(e) {
		c = jQuery(this).attr('class').split(' ');
		targetClass=c[1];
		jQuery('.still').each(function(){
			d = jQuery(this).attr('class').split(' ');	
			this_class=d[1];
			if(this_class==targetClass){ jQuery(this).children('.overlay, .text').css({'display':'block'}); }
		});
	});
	jQuery('.still').live('mouseleave', function(e) {
		jQuery('.still').children('.overlay, .text').css({'display':'none'});
	});
	
	jQuery('.video').live('mouseenter', function(e) {
			jQuery(this).children('.text').css({'display':'block'});
			//jQuery(this).children('.perma').css({'display':'block'});
	});
	jQuery('.video').live('mouseleave', function(e) {
			jQuery(this).children('.text').css({'display':'none'});
			//jQuery(this).children('.perma').css({'display':'none'});
	 });
	
	jQuery('.article').live('mouseenter', function(e) {
			jQuery(this).children('.overlay').css({'display':'block'});
			jQuery(this).children('.text').css({'display':'block'});
			//jQuery(this).children('.perma').css({'display':'block'});
	});
	jQuery('.article').live('mouseleave', function(e) {
			jQuery(this).children('.overlay').css({'display':'none'});
			jQuery(this).children('.text').css({'display':'none'});
			//jQuery(this).children('.perma').css({'display':'none'});
	 });
	
	jQuery('#slideshow').live('click', function() {
		if(!my_slideshowActive){
			jQuery('#pagination').startSlideShow();
			 jQuery(this).removeClass('play');
			 jQuery(this).addClass('pause');
			my_slideshowActive=true;
		}else{
			jQuery('#pagination').stopSlideShow();
			 jQuery(this).removeClass('pause');
			 jQuery(this).addClass('play');
			my_slideshowActive=false;
		}
		return false;
	});
		
		
	jQuery('#toggle_btn a').live('click', function(e) {
		if(!isOpen){
			jQuery('#info').fadeTo(0,1);jQuery("#info div.set-info").css({'display':'block'});
			jQuery('#info').stop().animate({height:'216px'},600,'linear');
			jQuery('#add_to_lightbox').stop().animate({bottom: '263px'},600,'linear');
			jQuery('.social-media-gallery').stop().animate({bottom: '266px'},600,'linear');
			jQuery(this).addClass('active');
			isOpen=true;
		}else{
			jQuery('#info').stop().animate({height:'0px'},600,'linear',function(){jQuery('#info').fadeTo(0,0);jQuery("#info div.set-info").css({'display':'none'});});
			jQuery('#add_to_lightbox').stop().animate({bottom: '47px'},600,'linear');
			jQuery('.social-media-gallery').stop().animate({bottom: '50px'},600,'linear');
			jQuery(this).removeClass('active');
			isOpen=false;
		}
	 e.preventDefault();
	});
	var add_btn_active=true;
	jQuery('#add_to_lightbox a').live('click', function(e){
		e.preventDefault();
		if(add_btn_active){
		id = jQuery('#pagination a.activeslide').attr('id');
		//now add image id to lightbox
		addLightbox(id);
		}
	});
	
	jQuery('#create-pdf a, #create-pdf-2').live('click', function(e){
		e.preventDefault();
		order = jQuery('input#order').val();
		if(jQuery('#lightbox-list').children().length>0){
		jQuery('#pdf-form').attr("action", "/wp-content/themes/sam-robinson/scr/create_pdf.php?order="+order);
		jQuery('#pdf-form').submit();
		}
	});
	
	jQuery('#save-order').live('click', function(e){
		e.preventDefault();
		order = jQuery('input#order').val();
		if(order!=''){
			saveOrder();
		}
	});
	
	jQuery('a.delete').live('click', function(e){
		e.preventDefault();
		id = jQuery(this).attr('rel');
		deleteImage(id,'false');
	});
	
	jQuery('a#delete-all').live('click', function(e){
		e.preventDefault();
		id = jQuery(this).attr('rel');
		deleteImage(id,'true');
	});
	
	
})(jQuery);

function lightviewUpdate() {
  Lightview.updateViews();
};


/* Lightbox functions  */
function addLightbox(id){
		
		var ajaxRequest;  // The variable that makes Ajax possible!
		 try{
		   // Opera 8.0+, Firefox, Safari
		   ajaxRequest = new XMLHttpRequest();
		  // alert('Opera 8.0+, Firefox, Safari');
		 }catch (e){
		   // Internet Explorer Browsers
		   try{
			  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			  //alert('Msxml2.XMLHTTP');
		   }catch (e) {
			  try{
				 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				 //alert('Microsoft.XMLHTTP');
			  }catch (e){
				 // Something went wrong
				 alert("Your browser broke!");
				 return false;
			  }
		   }
		 }
		 // Create a function that will receive data 
		 // sent from the server and will update
		 // div section in the same page.
		 ajaxRequest.onreadystatechange = function(){
		 //alert(ajaxRequest.readyState);
		   if(ajaxRequest.readyState == 4){
			   if(ajaxRequest.status  == 200) {
					//document.getElementById("small_images_holder").innerHTML=ajaxRequest.responseText;
					//document.getElementById("lightbox_link").innerHTML=ajaxRequest.responseText;
					jQuery('#lightbox a').html(ajaxRequest.responseText);
					add_btn_active=true;
					jQuery('#add_to_lightbox').stop().fadeTo(300,1);
					  }else {
				 }
		   }
		 }
		add_btn_active=false;
		jQuery('#add_to_lightbox').stop().fadeTo(300,0);
		ajaxRequest.open("GET", "/wp-content/themes/sam-robinson/scr/add_lightbox.php?int_image_id="+id, true);
		ajaxRequest.send(null);
}

function deleteImage(image,delete_all){
			
		var ajaxRequest;  // The variable that makes Ajax possible!
		 try{
		   // Opera 8.0+, Firefox, Safari
		   ajaxRequest = new XMLHttpRequest();
		  // alert('Opera 8.0+, Firefox, Safari');
		 }catch (e){
		   // Internet Explorer Browsers
		   try{
			  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			  //alert('Msxml2.XMLHTTP');
		   }catch (e) {
			  try{
				 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				 //alert('Microsoft.XMLHTTP');
			  }catch (e){
				 // Something went wrong
				 alert("Your browser broke!");
				 return false;
			  }
		   }
		 }
		 // Create a function that will receive data 
		 // sent from the server and will update
		 // div section in the same page.
		 ajaxRequest.onreadystatechange = function(){
		 //alert(ajaxRequest.readyState);
		   if(ajaxRequest.readyState == 4){
			   if(ajaxRequest.status  == 200) {
					location.reload();
					  }else {
				 }
		   }
		 }
		ajaxRequest.open("GET", "/wp-content/themes/sam-robinson/scr/delete_img.php?image="+image+"&delete_all="+delete_all, true);
		ajaxRequest.send(null);
}

function getLightboxCount(){
		
		var ajaxRequest;  // The variable that makes Ajax possible!
		 try{
		   // Opera 8.0+, Firefox, Safari
		   ajaxRequest = new XMLHttpRequest();
		  // alert('Opera 8.0+, Firefox, Safari');
		 }catch (e){
		   // Internet Explorer Browsers
		   try{
			  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			  //alert('Msxml2.XMLHTTP');
		   }catch (e) {
			  try{
				 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				 //alert('Microsoft.XMLHTTP');
			  }catch (e){
				 // Something went wrong
				 alert("Your browser broke!");
				 return false;
			  }
		   }
		 }
		 // Create a function that will receive data 
		 // sent from the server and will update
		 // div section in the same page.
		 ajaxRequest.onreadystatechange = function(){
		 //alert(ajaxRequest.readyState);
		   if(ajaxRequest.readyState == 4){
			   if(ajaxRequest.status  == 200) {
					//document.getElementById("small_images_holder").innerHTML=ajaxRequest.responseText;
					//document.getElementById("lightbox_link").innerHTML=ajaxRequest.responseText;
					jQuery('#lightbox a').html(ajaxRequest.responseText);
					  }else {
				 }
		   }
		 }
		ajaxRequest.open("GET", "/wp-content/themes/sam-robinson/scr/get_lightbox.php", true);
		ajaxRequest.send(null);
}

function saveOrder(){
		
		var ajaxRequest;  // The variable that makes Ajax possible!
		 try{
		   // Opera 8.0+, Firefox, Safari
		   ajaxRequest = new XMLHttpRequest();
		  // alert('Opera 8.0+, Firefox, Safari');
		 }catch (e){
		   // Internet Explorer Browsers
		   try{
			  ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			  //alert('Msxml2.XMLHTTP');
		   }catch (e) {
			  try{
				 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				 //alert('Microsoft.XMLHTTP');
			  }catch (e){
				 // Something went wrong
				 alert("Your browser broke!");
				 return false;
			  }
		   }
		 }
		 // Create a function that will receive data 
		 // sent from the server and will update
		 // div section in the same page.
		 ajaxRequest.onreadystatechange = function(){
		 //alert(ajaxRequest.readyState);
		   if(ajaxRequest.readyState == 4){
			   if(ajaxRequest.status  == 200) {
					  }else {
				 }
		   }
		 }
		order = jQuery('input#order').val();
		ajaxRequest.open("GET", "/wp-content/themes/sam-robinson/scr/save_order.php?order="+order, true);
		ajaxRequest.send(null);
}
	 
	 
	 
	

