/*
 * jQuery Classic Catering Custom Gallery
 * Version: 0.0.0
 *
 * Author: Chris Rivers
 * http://chrisriversdesign.com
 *
 *
 * Changelog: 
 * Version: 0.0.0
 *	Init Build
 *
 */

var carousel;
var sharehtml;
var shareImageID;  


$(document).ready(function(){ // Auto Shadowbox Logic
	
	SITE_URL = $('body').attr("site_url");
	
	/* Before Jcarousel for Gallery Type
	------------------------ */
	var GalleryType = $('.gallery-primary-navigation').attr('gallerytype');
	
	if( GalleryType ){
		if( GalleryType == 'Cuisine' ){ // Cuisine
			//alert(GalleryType);
			$(".gallery-thumb.vgal").remove();
			$(".cuisineOpt").addClass('bold');
		} else if( GalleryType == 'Venues' ){ // Venues
			//alert(GalleryType);
			$(".gallery-thumb.cgal").remove();
			$(".venuesOpt").addClass('bold');
		} 
	} else {
		$(".allOpt").addClass('bold');	
	}
	
	/* New Gallery Logic
	-----------------------------------------------*/
	if( $("body").hasClass('Photo') ){
		$('#mycarousel').jcarousel({ 
			buttonNextHTML : null, 
			buttonPrevHTML : null 
		});
	}
	var imgSrc = $(".carouselimages").first().attr("large");
	var initContent = $(".carouselimages").first().attr("caption");
	var shareImageID = $(".carouselimages").first().attr("photoID");
	
	
	//------------------------- Sharing to Gallery  ------------------------------//
	
	/* Background to Gallery Logic
	-----------------------------------------------*/
	var subTitle = $("#footer .col1 h1").text();
	var subDesc = $("#footer .col1 p").text();
	var subImage = $('body').attr("imageID");
	//var subImage = $('body').attr("rand_image");
	
	/**** Default Template Footer 
	      Goto Gallery and Open this image */
	$(".footerinner div.col1 h1.galleryTitle").click(function(){
			// window.location = SITE_URL + "photo-gallery" + "?GalleryImage=" + subImage + "&GalleryTitle=" + subTitle + "&GalleryDesc=" + subDesc;
			window.location = SITE_URL + "photo-gallery" + "/" + subImage; 
	});
	
	// Homepage Only
	$(".footerinner h2.galleryTitle").click(function(){
			
			/*var phototitle = $(this).attr("ptitle");
			var photodesc = $(this).attr("pdesc");;
			
			window.location = SITE_URL + "photo-gallery" + "?GalleryImage=" + subImage + "&GalleryTitle=" + phototitle + "&GalleryDesc=" + photodesc;*/
			
			window.location = SITE_URL + "photo-gallery" + "/" + subImage;
	});
	
	//******** End Default Footer ***********/
		
	var GalleryImage = $('.gallery-primary-navigation').attr('galleryImage');
	var GalleryCaption = $('.gallery-primary-navigation').attr('galleryCaption');
	
	if( GalleryImage != '' ){
		imgSrc = GalleryImage;
		initContent = GalleryCaption;
	}
	
	if( $('.gallery-primary-navigation').attr('galleryID') != ''){
		shareImageID = $('.gallery-primary-navigation').attr('galleryID');
		shareImageID = shareImageID;
	}
	
	//-------------------------------------------------------//
	
	// Update Caption Variable
	$('.galFooter .col1 .textTarget').html(initContent);
	subTitle = $("#footer .col1 h1").text();
	subDesc = $("#footer .col1 p").text();
	
	$.backstretch(imgSrc, {
		//centeredY: false
	});  
	       
	
	// Custom Footer Controls
	$(".galFooter .col2").append($(".jcarousel-skin-classic"));
	$(".galFooter .col2").prepend($(".gallery-primary-navigation"));
	$(".galFooter .col2").append($("<div class='gallery-submenu'><a class='View'>Sort Galleries</a><span class='links'></span></div>"));	
	
	$("body.Photo.Gallery .gallery-submenu span.links").html
													("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
															+ "contact-us'> Contact Us |</a><span class='num'> 410-356-1666</span>"
													);
													
	$("body.Photo.Gallery .gallery-submenu span.links a.share").live("click", function(){
		_gaq.push(['_trackEvent',  'gallery', 'click', 'share']); // JS way to add click event to the links	
	});
	
	$("body.Photo.Gallery .gallery-submenu span.links a.contactshare").live("click", function(){
		_gaq.push(['_trackEvent',  'gallery', 'click', 'contact us']); // JS way to add click event to the links	
	});
													
	// $(".gallery-submenu span.links").append("<span class='num'> 410-356-1666</span>");
													
	$("#footer .col1 .textTarget").after($("body.Photo.Gallery .gallery-submenu span.links"));
	// sharehtml = $("body.Photo.Gallery .gallery-submenu span").html();
	
	$("body.Photo.Gallery .gallery-submenu").prepend($("ul.viewoptions"));
	$("body.Photo.Gallery .gallery-submenu .View").click(function(){
		$("ul.viewoptions").slideToggle("fast");
	});
	
	// Exception For Gallery
	if( $("body").hasClass('Photo') ){
		addthis.button('.share');
	}
	
	carousel = $('#mycarousel').data('jcarousel');
		
});

/* Gallery Click Events
-----------------------------------------------*/

$('#prevImage').live('click', function(){
	var nextImg = $('.current').parent().prev();
	var jIndex = parseInt(nextImg.attr('jcarouselindex'),10);
   
   if (jIndex) {            
      var nextImgSrc = nextImg.find('img').attr('large');                  
      
      $('.current').removeClass('current');
      
      nextImg.find('img').addClass('current');                       
      
      $('#backstretch img').attr('src', nextImgSrc);            
      
      // Image caption
      var nextImgCaption = nextImg.find('img').attr('caption');      
      //$('#captionTarget').html(nextImgCaption);
      $('.galFooter .col1 .textTarget').html(nextImgCaption);
	  
	  subTitle = $("#footer .col1 h1").text();
	  subDesc = $("#footer .col1 p").text();
	  shareImageID = nextImg.find('img').attr('photoID');
	  
	  $("body.Photo.Gallery .gallery-submenu span").html
													("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
															+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
													);

	  $("#footer .col1 span.links").html
									("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
											+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
											+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
											+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
									);
	  
		// Exception For Gallery
		if( $("body").hasClass('Photo') ){
			addthis.button('.share');
		}
	  
      carousel.scroll(jIndex);        
   }            
});

/*$('.min-gallery').live('click', function(){
   if ($(".gallery-container").css("display") == 'none') {
      $("#wrap").animate({"top": "-=80px"}, "medium", function() {
         $('.gallery-container').slideToggle(400);          
         $('.min-gallery').html('Minimize');                                        
      });
   } else {
      $("#wrap").css({
          'position': 'relative'
      });
      $('.gallery-container').slideToggle(400, function() {
         $("#wrap").animate({"top": "+=80" + "px"}, "medium");
         $('.min-gallery').html('Maximize');
      });
   }
});*/

$('#nextImage').live('click', function(){
    var nextImg = $('.current').parent().next();
    var jIndex = parseInt(nextImg.attr('jcarouselindex'),10);
    
    // Image caption
    var nextImgCaption = nextImg.find('img').attr('caption');      
    //$('#captionTarget').html(nextImgCaption);
	$('.galFooter .col1 .textTarget').html(nextImgCaption);
           
    if (jIndex) {
        var nextImgSrc = nextImg.find('img').attr('large');            
        $('.current').removeClass('current');
        nextImg.find('img').addClass('current');               
        $('#backstretch img').attr('src', nextImgSrc);
		
		subTitle = $("#footer .col1 h1").text();
		subDesc = $("#footer .col1 p").text();
		shareImageID = nextImg.find('img').attr('photoID');
		
		$("body.Photo.Gallery .gallery-submenu span").html
													("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
															+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
													);
													
		$("#footer .col1 span.links").html
									("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
											+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
											+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
											+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
									);
		
		// Exception For Gallery
		if( $("body").hasClass('Photo') ){
			addthis.button('.share');
		}
		       
        carousel.scroll(jIndex);        
    }      
});

$('.gallery-thumb img').live('click', function(){         

    $('.current').removeClass('current');
    
    $(this).addClass('current');           
    
    var imgSrc = $(this).attr('large');
    
    $('#backstretch img').attr('src', imgSrc);
	
	$('.galFooter .col1 .textTarget').html($(this).attr('caption'));
	
	subTitle = $("#footer .col1 h1").text();
	subDesc = $("#footer .col1 p").text();
	shareImageID = $(this).attr('photoID');
	
	$("body.Photo.Gallery .gallery-submenu span").html
													("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
															+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
															+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
													);
													
	$("#footer .col1 span.links").html
								("<a addthis:url='" + SITE_URL + "photo-gallery" + "/" 
										+ shareImageID + "' class='share' href='" + SITE_URL + "photo-gallery" + "/" 
										+ shareImageID + "'>Share This Gallery |</a><a class='contactshare' href='" + SITE_URL 
										+ "contact-us'> Contact Us |</a><span> 410-356-1666</span>"
								);
    
	// Exception For Gallery
	if( $("body").hasClass('Photo') ){
		addthis.button('.share');
	}
	
});        

