$(document).ready(function(){
	initGallery();
	initBrowsing();
	initModalswitching();
})

function initModalswitching(){
	$('.nog-galerye').change(function() {
		tb_show('','/photogalleries/subgallery/'+$(this).val()+'/?modal=true&width=900&height=486');
	});
}

function initBrowsing(){
    /*trmb = $('.large a');
    trmb.each(function(i){
      if($(this).attr('id') == 0){
      	$(this).attr('style', 'visibility:hidden');
			}else{
				$(this).attr('class', 'visibleonhover');
				$(this).attr('style', 'visibility:hidden');
    		$(this).click(function() {
        	switchImage($(this).attr('id'),$('#id').attr('value'), $('#model').attr('value'));
  	   });
  	 }
    });*/
    
    $('.large').hover(
      function () {
      	voh = $('.visibleonhover');
       	voh.each(function(i){
       		$(this).attr('style', '');
				});
      }, 
      function () {
      	voh = $('.visibleonhover');
        voh.each(function(i){
					$(this).attr('style', 'visibility:hidden');
				});
      }
    );
}

function loadPiece(href,divName) {
   loading = '<div class="loader"><img src="/img/frontend/thickbox/loadingAnimation.gif"></div>';
   $(divName).html(loading);
   $(divName).load(href, {}, function(){
       //initToolTips();
       var divPaginationLinks = divName+" #pagination a";
       $(divPaginationLinks).click(function() {
           var thisHref = $(this).attr("href");
           loadPiece(thisHref,divName);
           return false;
       });
   });
}
function loadPiecePrep(href,divName) {
   var divPaginationLinks = divName+" #pagination a";
   $(divPaginationLinks).click(function() {            
	 		 var thisHref = $(this).attr("href");
       loadPiece(thisHref,divName);
       return false;
   });
} 

function initGallery(){
  trmb = $('.thumbs a');
	trmb.each(function(i){
		$(this).click(function() {
			switchImage($(this).attr('id'),$('#id').attr('value'), $('#model').attr('value'));
			return false;
		});
	});

//	if(trmb.length > 0) {
//		var action = 'pause';
//		var interval  = 5 * 1000; // number of seconds to show image.
//		var intervalID;
//
//		$('.slideshow-actions a').live('click', function() {
//			if(action == 'pause') {
//				$(this).html('Pause');
//				action = 'play';
//			} else {
//				$(this).html('Play');
//				action = 'pause';
//			}
//
//			if(action == 'play') {
//				intervalID = setInterval('alert(\'Changing image\')', interval);
//			} else {
//				clearInterval(intervalID);
//			}
//			return false;
//		});
//	}
}

function switchImage(id, content_id, model){
	current_content = '<div class="loader"><img src="/img/frontend/thickbox/loadingAnimation.gif"></div>';
	
	$('#large').html(current_content);
	
	$.get('/'+model+'/gallery_item/'+content_id+'/'+id, {}, function(data) {
        current_content = buildHTML(data);
        setHTML(current_content);
    });
}

function buildHTML(data){
	html = data;
		
	return html;
}

function setHTML(html){
	$('#large').html(html);
}

