////////////////////////////////////////////////

/// PROJECTS pagination

function doPaginationProj (num) {
  /*$('#content').append("<div id='hotspot'></div>");***************************/
  numofdots = num;
	
  $('.pg').hide(); // hide all DIVs (Pages)
  $('#pg1').show(); // show first DIV
  
  var currentURL = $(location).attr('href'); //Get URL
  var strsplit = currentURL.split("_");
  //alert(strsplit[2]);
  //
  var i = 1; // Generate pagination

  while(i < num + 1){ 
     $('.contentbtm').append("<span class='dots' id='"+i+"' >&#8226;</span>") ;     
     i++;
   }
   
  $('.contentbtm .hint').hide();
  $('.contentbtm #1').addClass("active");
  $('.contentbtm #1').addClass("clicked"); 
   
  $('.contentbtm .dots').click(function() {
										
		if ($(this).hasClass('active')) {
		    //
        } else {			 						 
          var currentId = $(this).attr('id');
		  if (currentId==1) {
			 removeFrameProj ('#frame');
		     $('#pg1').fadeIn();
			 $('.dots').removeClass('active');
			 $('.dots').removeClass("clicked"); 
		     $('.contentbtm #1').addClass('active');
		     $('.contentbtm #1').addClass('clicked');
		  } else {
			 $('#overlay').fadeOut(function() { 
               removeFrameProj ('#frame');
		       var picCount = currentId - 1;
		       callFrameProj('php/show_image.php?id=gallery/'+strsplit[2]+ picCount, currentId, num);
             }); 
		  }
		}
		
  });
  $('.contentbtm').append("&nbsp;&nbsp;&nbsp;<span class='hint'></span>") ;  
  
  $('#hotspot').click(function() { // click anywhere to go to page 2 ***************************
	  $('.pg').hide();
	  //
	  var currentURL = $(location).attr('href'); //Get URL
      var strsplit = currentURL.split("_");
	  callFrameProj('php/show_image.php?id=gallery/'+strsplit[2]+ "1", 2);	
  });
}

// ---- GO TO NEXT IMAGE FUNCTION ---- //

function nextpageclick (num) {
	    var currentURL = $(location).attr('href'); //Get URL
        var strsplit = currentURL.split("_");
	    // alert('click');
		frameid = $('iframe').attr('class');
		currentFrameId = "";
		currentFrameId = parseInt(frameid);
				
		$('#overlay').fadeOut('', function() {
            removeFrameProj ('#frame');
		    var picCount = currentFrameId;
			
			if (currentFrameId!=numofdots) {
		       callFrameProj('php/show_image.php?id=gallery/'+strsplit[2]+ picCount, currentFrameId+1);
			}
			else {
			   $('#pg1').fadeIn();
			   //$('.menu_bg').css('visibility','hidden');
			   //$('#gallery').hide();
			   $('.dots').removeClass('active');
			   $('.dots').removeClass("clicked"); 
		       $('.contentbtm #1').addClass('active');
		       $('.contentbtm #1').addClass('clicked');
			}
        });
}

////---- END //

function callFrameProj (url, currentId, num) {
	//alert ('callFrameProj');
    $('#overlay').css('display','block');
	$('.dots').removeClass('active');
	$('.dots').removeClass("clicked"); 
    $('.contentbtm .hint').html('Loading...');
	$('.contentbtm .hint').hide();
	
	if (currentId!=1) {
	   //$('.menu_bg').css('visibility','visible');
	   $('.contentbtm .hint').delay(0).fadeIn();
	   $('.contentbtm #' + currentId).addClass('active');
	   $('.contentbtm #' + currentId).addClass('clicked');
       $('#overlay').append("<IFRAME src ='"+url+"' id='frame' class='"+currentId+"' width='100%' scrolling:'no' frameborder='0' onload='resize_iframe()'></iframe>");
	   // Show Pan Hint
	   if ($('#hint').html()!='done') {
		  $('#hint').html('done');
	      /*$('.contentbtm .hint').append("Move your mouse over image to pan") ; 
	      $('.contentbtm .hint').delay(800).fadeIn('',function() {
	         $('.contentbtm .hint').delay(4000).fadeOut();
          });*/
	   }
	   $('#pg1').fadeOut();
	}
	else {
	   $('.contentbtm #1').addClass('active');
	   $('.contentbtm #1').addClass('clicked');
	   //$('.menu_bg').css('visibility','hidden');
    }
	
	
    $('#frame').load (function() { /*callback(this);*/ 
	   frameid = $('iframe').attr('class');	
	   $('.contentbtm .hint').hide();
	   /*$('.contentbtm .hint').append(frameid);*/
	});
}

function removeFrameProj (obj) {
       $('#frame').empty().remove();
	   $('#overlay').css('display','none');
}

////////////////////////////////////////////////

// Window resize, scales image in iFrame

function resize_iframe()
{
	var height=window.innerWidth; //Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight; //IE
	}
	document.getElementById("frame").style.height=parseInt(height-
	document.getElementById("frame").offsetTop-0)+"px";
	
	$('iframe').css({
			width		: $(window).width() -0,
			height		: $(window).height()-0,
	});
}

$(document).ready(function(){
	
	$(window).resize(function(){
		$('#overlay').css({
			width		: $(window).width() -0,
			height		: $(window).height()-0,
		});	
		$('iframe').css({
			width		: $(window).width() -0,
			height		: $(window).height()-0,
		});
	});
	
});

