// NEWSLETTER POPUP
function newsletter() {
  // Set Height of Overlay
  $('#overlayLoad').css('height',$(document).height());
  // Fade In Overlay
	$('#overlayLoad').fadeIn();
	$('#signUp').center();
	$('#signUp .closeSignUp').click(function() {
    $('#signUp').fadeOut();
    $('#overlayLoad').fadeOut();
  });
}

// REPLACE TARGET WITH A CLASS OF NEWWINDOW
function replaceTarget() {
  if (!document.getElementsByTagName('a')) return false;
  $('a[target]').addClass('newwindow').removeAttr('target');
}

// OPEN WEB STANDARD POPUP
function strictNewWindow() {
  if (!document.getElementsByTagName('a')) return false;
  $('a.newwindow').click(function() {
		window.open($(this).attr('href'));
    return false;
	});
}

// CLEAR SEARCH BOX
function clearSearchBox() {
	if (!document.getElementById('txtSearch')) return false;
	$('#txtSearch').focus(function() {
    if ($(this).val() == 'SEARCH') {
      $(this).val('');
	  }
  });
}

// BANNER ROTATION
function initializeCycle() {
	if (!$('.pics a').length > 0) return false;
  $('.pics a').cycle('shuffle');
}

// NAVIGATION
function navigation() {
  $('.buttonWrap h3 a').hide();
  $('.buttonWrap h3').addClass('inactive');
  $('.buttonWrap h3').click(function() {
    if($(this).hasClass('inactive')) {
      $('.toggleInfo').slideUp();
      $('.buttonWrap h3').removeClass('active');
      $('.buttonWrap h3').addClass('inactive');
      $(this).removeClass('inactive');
      $(this).addClass('active');
      $(this).parent().find('.toggleInfo').slideDown();
    } else {
      if($(this).hasClass('active')) {
        $('.toggleInfo').slideUp();
        $('.buttonWrap h3').removeClass('active');
        $('.buttonWrap h3').addClass('inactive');
      }
    }
  });
  // Close the Pop Up
  var close = '<p class="close">Close</p>';
	$('.toggleInfo').append(close);
	$('.buttonWrap .close').click(function() {
    $(this).parent('.toggleInfo').slideUp();
    $(this).parent().parent().find('h3').removeClass('active');
    $(this).parent().parent().find('h3').addClass('inactive');
  });
}


//*****Load all functions**************************************************//
$(document).ready(function(){
  newsletter();
  clearSearchBox();
  replaceTarget();
  strictNewWindow();
  initializeCycle();
	navigation();
});