$(document).ready(function() {

var formatParagraphs = function() {
  var scrollpane = $('#scrollpane');
  var maxHeight = $(scrollpane).height() * 2;
  var totalChildHeight = 0;

  $(scrollpane).children().each(function(index, child) {
    totalChildHeight += $(child).outerHeight(true);
  });

  if (totalChildHeight < maxHeight) {
    var paragraphHeight = $(scrollpane).find('p:first').outerHeight(true);

    var paragraphQty = parseInt((maxHeight - totalChildHeight) / paragraphHeight);

    for (i = 0; i < paragraphQty; i++) {
      $(scrollpane).append('<p>&nbsp;</p>');
    }
  }
}

  $('#trigger').addClass("nonSelected");

  $('#trigger').click(function() {

  if($(this).hasClass('nonSelected')){
    $('#panel').slideToggle();
		$('#arrow-img').attr("src", "/wp-content/themes/netaffinity-hotel/images/arrow-down.jpg");
		$("#trigger").removeClass("nonSelected");
		Cufon.refresh();
$('#featureoffer').fadeOut();
  }
  else {
		$('#panel').slideToggle();
		$('#arrow-img').attr("src", "/wp-content/themes/netaffinity-hotel/images/arrow-up.jpg");
		$('#trigger').addClass("nonSelected");
		$('#featureoffer').fadeIn(2000);
  }

    return false;
  });

  $('#tab_row .tab').click(function() {
  	if (!$('#panel').is(':visible')) {
  	  $('#panel').slideToggle();
    }

  	$('#tab_row .tab').removeClass('active');
  	$(this).addClass('active');

  	if (!$(this).is('#trigger')) {
  	  /*var tab_id_parts = $(this).attr('id').split('_');
  	  var slideshow_img_id = 'sl_img_' + tab_id_parts[1];

  	  if (!$('#supersize #' + slideshow_img_id).is(':visible')) {
    	  $('#supersize .slideshow-img').hide();
    	  $('#supersize #' + slideshow_img_id).fadeIn('normal');
  	  }*/
  	}

	  var post_id_parts = $(this).find('.post-id').val().split(':');
	  var post_id = post_id_parts[0];
	  var col_off = post_id_parts[1];

	  if (post_id != undefined) {
  		var post_data = {'post_id': post_id};
  		var scrollpane = $('#scrollpane');

  		$(scrollpane).empty().removeAttr('style').addClass('loading');

  		$.post('/get_post_ajax.php',
  		  post_data,
  		  function (response) {
  		    $(scrollpane).empty().removeClass('loading');
  		    $(scrollpane).html(response);
  		    formatParagraphs();

  		    if (col_off != 'col_off') {
  		      $(scrollpane).columnize({columns: 2, lastNeverTallest: true});
  		    }

  		    $(scrollpane).jScrollPane();

  		    shutterReloaded.init();
  		    Cufon.refresh();
  		  }
  		);
	  }
  });




   $('#sub-links ul li.gal').click(function() {
     if (!$('#panel').is(':visible')) {
  	   $('#panel').slideToggle();
     }

     $('#tab_row .tab').removeClass('active');

     var post_id_parts = $(this).find('.post-id').val().split(':');
     var post_id = post_id_parts[0];
     var col_off = post_id_parts[1];

     if (post_id != undefined) {
	     var post_data = {'post_id': post_id};
	     var scrollpane = $('#scrollpane');

	     $(scrollpane).empty().removeAttr('style').addClass('loading');

	     $.post('/get_post_ajax.php',
	       post_data,
	       function (response) {
           $(scrollpane).empty().removeClass('loading');
           $(scrollpane).html(response);
           formatParagraphs();

           if (col_off != 'col_off') {
             $(scrollpane).columnize({columns: 2, lastNeverTallest: true});
           }

           $(scrollpane).jScrollPane();

           shutterReloaded.init();
		       Cufon.refresh();
	       }
	     );
     }
  });
});
