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

// Pagination for non-project pages

function doPagination (num) {
  $('#content').append("<div id='hotspot'></div>");
  $('.pg').hide();
  $('#pg1').show();
  ///
  numofdots = num; // number of pages
  var i = 1; // Generate pagination
  currentId = 1;

  while (i < num + 1) { 
     $('.contentbtm').append("<span class='dots' id='"+i+"' >&#8226;</span>") ;     
     i++;
  }
   
  $('.contentbtm #1').addClass("active"); //make active state
  $('.contentbtm #1').addClass("clicked"); // remove hover color
  
  $('.contentbtm').append("&nbsp;&nbsp;&nbsp;<span class='hint'></span>") ; 
  //$('.contentbtm').append("&nbsp;&nbsp;&nbsp;<span class='test'></span>") ; 
  $('.contentbtm .hint').html('Loading...');
  $('.contentbtm .hint').hide();
  
  $('.contentbtm .dots').click(function() {
		if ($(this).hasClass('active')) {
		    //
        } else {
            currentId = $(this).attr('id');
		    $('.test').html(currentId);
		    $('.dots').removeClass('active');
			$('.dots').removeClass('clicked');
		    $(this).addClass('active');
		    $(this).addClass('clicked');
		
	    	if ($(this).attr('isImage')) { // if link is for an image
		        $('.pg').hide();
	            callFrame($(this).attr('isImage'));
            } else { //if not
                $('.pg').hide();
		        $('#pg'+currentId).fadeIn();
			    removeFrame('#frame');
            }
        }
  });
  
  $('#hotspot').click(function() { // click anywhere to go next ***************************
	  $('.dots').removeClass('active');
	  //removeFrame('#frame');
	  $('.pg').hide();
	  
	  if ( currentId != numofdots ) {
		 nextId=parseInt(currentId)+1;
		 currentId = nextId;
		 if ( $('.contentbtm #'+nextId).attr("isImage")!=null ){ //if next page isImage
		     $('.pg').hide();
	         callFrame( $('.contentbtm #'+nextId).attr('isImage') );
		 }
		 else { //if not, show pg as usual
	         $('#pg'+nextId).fadeIn();
		    
		 } 
		 $('.contentbtm #'+currentId).addClass('active');
		 $('.contentbtm #'+currentId).addClass('clicked');
      }	
	  else { //if current page is last, loop
		 currentId = 1;
         $('#pg1').fadeIn();
		 $('.contentbtm #1').addClass('active');
		 $('.contentbtm #1').addClass('clicked');
      }			
  });
}

function isImage (obj, url, num) {
	$(obj).attr("isImage", url);
	$('.test').append(num);
}

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

function callFrame(url) {
   $('.contentbtm .hint').fadeIn();
   if( $('#overlay').is(':hidden') ) {
       $('#overlay').css('display','block');
       $('#overlay').append("<IFRAME src ='"+url+"' id='frame' width='100%' scrolling:'no' frameborder='0' onload='resize_iframe()'></iframe>");
   }
   else {
       $('#frame').fadeOut('slow', function() {
	       $('#overlay').css('display','block');
		   $('#frame').empty().remove();
           $('#overlay').append("<IFRAME src ='"+url+"' id='frame' width='100%' scrolling:'no' frameborder='0' onload='resize_iframe()'></iframe>");
       });
   }
   $('#frame').load (function() {
	   $('.contentbtm .hint').hide(); // Hide Loading...
   });
}

// ---- GO TO NEXT IMAGE FUNCTION FOR NON-PROJECTS ---- //

function nextpageframe (num) { 
	  $('.dots').removeClass('active');
	  $('.pg').hide();
	  
	  if ( currentId != numofdots ) {
		 nextId=parseInt(currentId)+1;
		 currentId = nextId;
		 if ( $('.contentbtm #'+nextId).attr("isImage")!=null ){ //if next page isImage
		     $('.pg').hide();
	         callFrame( $('.contentbtm #'+nextId).attr('isImage') );
			
		 }
		 else { //if not, show pg as usual
	         $('#pg'+nextId).fadeIn();
			 removeFrame('#frame');
		    
		 } 
		 $('.contentbtm #'+currentId).addClass('active');
		 $('.contentbtm #'+currentId).addClass('clicked');
      }	
	  else { //if current page is last, loop
	     removeFrame('#frame');
		 currentId = 1;
         $('#pg1').fadeIn();
		 $('.contentbtm #1').addClass('active');
		 $('.contentbtm #1').addClass('clicked');
      }	
}

////---- END //



