(function($) {

    Drupal.behaviors.compactForm = {
        attach: function(context, settings) {		
            //cForm('#search .form-text', Drupal.t('Search...'));
			
			$('#splash .form-text').each(function(){
			  var defvalue = $(this).parents('.form-item').find('label').text();
			  cForm($(this), defvalue);
			});
        }
    };	
	
    Drupal.behaviors.splashBlock = {
        attach: function(context, settings) {	
			//var popID = $(this).attr('rel'); //Get Popup Name
			var popID = '#splash';
			//var popURL = $(this).attr('href'); //Get Popup href to define size

			//Pull Query & Variables from href URL
			//var query= popURL.split('?');
			//var dim= query[1].split('&');
			//var popWidth = dim[0].split('=')[1]; //Gets the first query string value

			//Define margin for center alignment (vertical   horizontal) - 
			//we add 80px to the height/width to accomodate for the padding  and border width defined in the css
			var popMargTop = ($(popID).height() + 20) / 3;
			var popMargLeft = ($(popID).width() + 180) / 2;

			//Fade in Background
			//$('body').append('<div id="overlay"></div>'); //Add the fade layer to bottom of the body tag.
			//$('#overlay').css({'filter' : 'alpha(opacity=80)'}); //.fadeIn()
			//Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 
			
			$('#overlay').hide();
			// Set a delay
			setTimeout(function() {
			// Do something after 15 seconds
			//$(popID, '#overlay').fadeIn();
			
			$('#overlay').fadeIn('slow');
			$(popID).css({
				'margin-top' : -popMargTop,
				'margin-left' : -popMargLeft
			  }).fadeIn();		
			}, 15000);
			
			//hide a div after 30 seconds
			//setTimeout( "$(popID, '#overlay').hide();", 30000 );
			
			$('.close').click(function() {
			   $(popID).remove();
			   $('#overlay').remove();
			   return false;
			});
        }
    };		
    // List to select
    Drupal.behaviors.listSelect = {
        attach: function(context, settings) {	
			$('ul.selectdropdown').each(function() {
				var $select = $('<select />');

				$(this).find('a').each(function() {
					var $option = $('<option />');
					$option.attr('value', $(this).attr('href')).html($(this).html());
					$select.append($option);
				});

			$(this).replaceWith($select);
		});
        }
    };		

	//.node-content a[href*="https://"], 
    Drupal.behaviors.externalLink = {
        attach: function(context, settings) {
            $('.external').click(function(){
            var url = $(this).attr('href');
            window.open(url, 'external');
            return false;
			});
        }
    };
	
	//Accordion
    Drupal.behaviors.accordSlide = {
        attach: function(context, settings) {	
		  $('.node-faq.mode-listing .content').hide();//.not('.content:first')
		
		  //$('.node-faq h2.node-title:first').addClass('slideon');
		
		  $('.node-faq.mode-listing h2.node-title').click(function() {
			$('.node-faq.mode-listing .content').slideUp('normal');
			//$(this).next().slideUp('normal');
			if($(this).siblings('.content').css('display') == 'none') {
				$(this).siblings('.content').stop(true, true).slideDown('normal').addClass('shown');
				$('.node-faq.mode-listing h2.node-title').removeClass('slideon');
				$(this).addClass('slideon');
			}
			else {
				$(this).siblings('.content').stop(true, true).slideUp('slow').removeClass('shown');
				$(this).removeClass('slideon');
			}
		
			return false;
		  });
        }
    };
    
	function cForm(selector,defvalue){
	  //var defvalue = $(selector).parents('.form-item').find('label').text();
	  if($.trim($(selector).val())==""){
	    $(selector).val(defvalue);
	  }
	  $(selector).focus(function(){
	    if($(selector).val()==defvalue){
		  $(selector).val("");
		}
	  });
		  
	  $(selector).blur(function(){
	    if($.trim($(selector).val())==""){
		  $(selector).val(defvalue);
		}
	  });
	}	
	

})(jQuery);
;

