/**** Add application wide javascripts below this point  ******/
$(document).ready(function() {
  $("#companies_block .list .image_0").eq(0).attr("src", $(".image_0").attr("rel"));
  $("#companies_block .list .image_1").eq(0).attr("src", $(".image_1").attr("rel"));
});




secondary_backgrounds = []; //global one for all background images...
primary_backgrounds = [];
event_cost = 0;
//background swapping on home page
function home_page_backgrounds(backgrounds, prefix, size){
  if(typeof(backgrounds) != undefined && backgrounds.length){
    for(var div_id in backgrounds){
      if(!size) jQuery('#'+prefix+div_id).css('background', "url('"+backgrounds[div_id]+"') no-repeat center center");
      else jQuery('#'+prefix+div_id).css('background', "url('/show_image/"+backgrounds[div_id]+"/"+size+".jpg') no-repeat center center");
    }
  }
}

/** GOOGLE MAP **/
function googlemap(){
  if(jQuery('#googlemap').length && GBrowserIsCompatible() ){
    var g_map = new google.maps.Map2(document.getElementById('googlemap'));
    g_map.enableScrollWheelZoom();
		g_map.setUIToDefault();
		var local_search = new google.search.LocalSearch();
		local_search.setSearchCompleteCallback(null, function(){		  
		  if(local_search.results[0]){
		    var resultLat = local_search.results[0].lat, resultLng = local_search.results[0].lng;
		    var latLng = new GLatLng(resultLat, resultLng);
        g_map.setCenter(latLng, 15);
        var gicon = new GIcon(G_DEFAULT_ICON);
	      var marker = new GMarker(latLng, {icon:gicon, title:jQuery('h1').text()});		      
	      GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(jQuery('#event_page .location .copy').html());
        });
        g_map.addOverlay(marker);
		  }
		});
		local_search.execute(jQuery('address.postcode').html()+', UK');
  }
}


/** DIALOG **/
function email_friend_dialog(){
  jQuery('#email_a_friend').dialog({autoOpen:false,modal:true});
  jQuery('.send_to_friend').click(function(){
    jQuery('#email_a_friend').dialog('open');
    jQuery('#email_a_friend').dialog('option', 'title', 'Send to a Friend');
    jQuery('#email_a_friend form').show();
    email_friend_ajax_send();
    return false;
  });
}
function email_friend_ajax_send(){
  jQuery('#email_a_friend form').submit(function(){
    var form_fields = jQuery('#email_a_friend form').serialize();
    jQuery.ajax({
      type:jQuery('#email_a_friend form').attr('method'),
		  url:jQuery('#email_a_friend form').attr('action') + '.ajax',
  		data: form_fields,
  		success: function(response){
  			jQuery('#email_a_friend form').html(response);
  		},
  		error:function(response){
  		  jQuery('#email_a_friend form').html(response);
  		}
    });
    return false;
  });
}

function login_warning(){
  jQuery('a[href=#login_warning]').addClass('login_dialog');
  var introcopy = '<img src="/images/forms/traffic-cone.gif" alt="warning" class="left"/><p>In order to access this exclusive content, you must be an IiE Registered User. Enter your username and password now.</p>';
  var noaccess = '<p>You do not have access to this piece of content.</p>';
  if(jQuery('#iie_login form').length){
    var login_form = '<form id="iie_login_form_modal" method="post" action="">'+jQuery('#iie_login form').html()+'</form>';
    jQuery('#login_required_dialog').html(introcopy+login_form);
  }else jQuery('#login_required_dialog').html(noaccess);
  jQuery('#login_required_dialog').dialog({autoOpen:false,modal:true, title:'Attention'});
  jQuery('a.login_dialog').click(function(){
    jQuery('#login_required_dialog').dialog('open');
    return false;
  });
}


/**** EVENT FORM ****/
function show_hide_delegates(val){
  if(val == 0) jQuery('.delegate_form').hide();
  else{
    jQuery('.delegate_form').each(function(){
      var num = parseInt(jQuery(this).attr('id').replace("delegate_", ""));
      if(num >= val) jQuery(this).hide().find('input').attr('disabled', true);
      else jQuery(this).show().find('input').removeAttr('disabled');
    });
  }
  var new_cost = ((val+1)*event_cost).toFixed(2);
  jQuery('#total_cost span em').html(new_cost);
}
function event_form(){
  if(!jQuery('#main_registrar_register_lead_contact').is(":checked")) jQuery('.delegate').hide().find('input').attr('disabled', true);
  else show_hide_delegates(parseInt(jQuery('#main_registrar_delegates').val()));

  if(jQuery('#main_registrar_register_lead_contact_table').is(":checked")) jQuery('#total_cost span em').html(event_table_cost);

  jQuery('#main_registrar_register_lead_contact').click(function(){ 
    jQuery('#delegates_intro').show(); 
    show_hide_delegates(parseInt(jQuery('#main_registrar_delegates').val()));
  });
  jQuery('#main_registrar_register_as_individual').click(function(){
    jQuery('.delegate').hide().find('input').attr('disabled', true);
    jQuery('#total_cost span em').html(event_cost);
  });
	jQuery('#main_registrar_register_lead_contact_table').click(function(){
    jQuery('.delegate').hide().find('input').attr('disabled', true);
    jQuery('#total_cost span em').html(event_table_cost);
  });
  
  jQuery('#main_registrar_delegates').change(function(){ show_hide_delegates(parseInt(jQuery(this).val())); });
}

/** ajax calendar links **/
function ajax_calendar(){
  jQuery('.cal_options .previous a, .cal_options .next a').click(function(){
    jQuery('#calendar_block').fadeTo('fast', 0.6);
    var clicked = this.href.substring(this.href.indexOf('?'));
    jQuery.ajax({
      type:'post',
      url:'/calendar_list.ajax'+clicked,
      success:function(response){
        jQuery('#calendar_block').replaceWith(response);
        ajax_calendar();
      },
      error:function(){ajax_calendar();}
    });
    return false;
  });
}

/**** ****/
jQuery(document).ready(function(){
  if(jQuery('#primary_featured_articles').length){
    jQuery('#primary_featured_articles').switcher({item:'.primary_feature', pagination:'#paginated_features', auto_rotate:true, rotate_time:11000, swap_container_class:true,speed:0});
    home_page_backgrounds(primary_backgrounds, 'primary_feature_', false);
  }
  if(jQuery('div.secondary_feature').length) home_page_backgrounds(secondary_backgrounds, 'secondary_feature_', false);
  if(jQuery('#secondary_images').length && jQuery('#secondary_images img').length > 1) jQuery('#secondary_images').switcher({item:'.image_holder', auto_rotate:true, rotate_time:5000, speed:"slow"});
  googlemap();
  
  if(jQuery('#news_archive').length) jQuery('#news_archive').slidingtree();
  if(jQuery('#email_a_friend_form').length){
    jQuery('#email_a_friend_form').hide();
    email_friend_dialog();
  }
  if(jQuery('.flickr a.gallery').length) jQuery('.flickr a.gallery').lightBox();
  if(jQuery('#secondary_images a.gallery').length) jQuery('#secondary_images a.gallery').lightBox();  
  login_warning();
  if(jQuery('#register_form').length) event_form();
  if(jQuery('#calendar_block').length) ajax_calendar();


	$("#other_hear").hint();
	if(jQuery("#contact_us_hear_from").val() == 6 || jQuery("#main_registrar_hear_from").val() == 6 ){
		$("#other_hear").css({"display":"block","float":"right"});
	}else{
		$("#other_hear").css("display","none");
	}
	jQuery("#contact_us_hear_from, #main_registrar_hear_from").change(function(){
		if($(this).val() == 6){
			$("#other_hear").css({"display":"block","float":"right"});
		}else{
			$("#other_hear").css("display","none");
		}
	});
	
	$("#callback_date").datepicker({dateFormat: "dd.mm.yy"});
	$("#callback_time").clockpick({	starthour : 0,
																	endhour : 23});
});



var block_items;
var current_block=0;
/***** Companies Block Rotator ************/
$(document).ready(function() {
    block_items = $("#companies_block .list img").hide().filter(":eq(0)").show().add("#companies_block .list img").size();
    if(block_items > 1) setInterval(auto_block,4000);
});

function auto_block() {
    $("#companies_block .list img:eq("+current_block+")").fadeOut("slow",function(){
      $(this).hide();
      current_block = ++current_block%block_items;
      ahead_block = current_block+1;
      $("#companies_block .list img:eq("+ahead_block+")").attr("src", $("#companies_block .list img:eq("+ahead_block+")").attr("rel"));
      $("#companies_block .list img:eq("+current_block+")").fadeIn("slow");
    });
}
(function($){$.fn.lightBox=function(settings){settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading:'/images/lightbox/ico-loading.gif',imageBtnPrev:'/images/lightbox/btn-prev.gif',imageBtnNext:'/images/lightbox/btn-next.gif',imageBtnClose:'/images/lightbox/btn-close.gif',imageBlank:'/images/lightbox/blank.gif',containerBorderSize:10,containerResizeSpeed:400,txtImage:'Image',txtOf:'of',keyToClose:'c',keyToPrev:'p',keyToNext:'n',imageArray:[],activeImage:0},settings);var jQueryMatchedObj=this;function _initialize(){_start(this,jQueryMatchedObj);return false;}
function _start(objClicked,jQueryMatchedObj){$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));}else{for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));}}
while(settings.imageArray[settings.activeImage][0]!=objClicked.getAttribute('href')){settings.activeImage++;}
_set_image_to_view();}
function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+settings.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+settings.imageBtnClose+'"></a></div></div></div></div>');var arrPageSizes=___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]}).show();$('#jquery-overlay,#jquery-lightbox').click(function(){_finish();});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){_finish();return false;});$(window).resize(function(){var arrPageSizes=___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});var arrPageScroll=___getPageScroll();$('#jquery-lightbox').css({top:arrPageScroll[1]+(arrPageSizes[3]/10),left:arrPageScroll[0]});});}
function _set_image_to_view(){$('#lightbox-loading').show();if(settings.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}else{$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();}
var objImagePreloader=new Image();objImagePreloader.onload=function(){$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);objImagePreloader.onload=function(){};};objImagePreloader.src=settings.imageArray[settings.activeImage][0];};function _resize_container_image_box(intImageWidth,intImageHeight){var intCurrentWidth=$('#lightbox-container-image-box').width();var intCurrentHeight=$('#lightbox-container-image-box').height();var intWidth=(intImageWidth+(settings.containerBorderSize*2));var intHeight=(intImageHeight+(settings.containerBorderSize*2));var intDiffW=intCurrentWidth-intWidth;var intDiffH=intCurrentHeight-intHeight;$('#lightbox-container-image-box').animate({width:intWidth,height:intHeight},settings.containerResizeSpeed,function(){_show_image();});if((intDiffW==0)&&(intDiffH==0)){if($.browser.msie){___pause(250);}else{___pause(100);}}
$('#lightbox-container-image-data-box').css({width:intImageWidth});$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:intImageHeight+(settings.containerBorderSize*2)});};function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();_set_navigation();});_preload_neighbor_images();};function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(settings.imageArray[settings.activeImage][1]){$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();}
if(settings.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(settings.txtImage+' '+(settings.activeImage+1)+' '+settings.txtOf+' '+settings.imageArray.length).show();}}
function _set_navigation(){$('#lightbox-nav').show();$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({'background':'transparent url('+settings.imageBlank+') no-repeat'});if(settings.activeImage!=0){if(settings.fixedNavigation){$('#lightbox-nav-btnPrev').css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnPrev+') left 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage-1;_set_image_to_view();return false;});}}
if(settings.activeImage!=(settings.imageArray.length-1)){if(settings.fixedNavigation){$('#lightbox-nav-btnNext').css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'}).unbind().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}else{$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+settings.imageBtnNext+') right 15% no-repeat'});},function(){$(this).css({'background':'transparent url('+settings.imageBlank+') no-repeat'});}).show().bind('click',function(){settings.activeImage=settings.activeImage+1;_set_image_to_view();return false;});}}
_enable_keyboard_navigation();}
function _enable_keyboard_navigation(){$(document).keydown(function(objEvent){_keyboard_action(objEvent);});}
function _disable_keyboard_navigation(){$(document).unbind();}
function _keyboard_action(objEvent){if(objEvent==null){keycode=event.keyCode;escapeKey=27;}else{keycode=objEvent.keyCode;escapeKey=objEvent.DOM_VK_ESCAPE;}
key=String.fromCharCode(keycode).toLowerCase();if((key==settings.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish();}
if((key==settings.keyToPrev)||(keycode==37)){if(settings.activeImage!=0){settings.activeImage=settings.activeImage-1;_set_image_to_view();_disable_keyboard_navigation();}}
if((key==settings.keyToNext)||(keycode==39)){if(settings.activeImage!=(settings.imageArray.length-1)){settings.activeImage=settings.activeImage+1;_set_image_to_view();_disable_keyboard_navigation();}}}
function _preload_neighbor_images(){if((settings.imageArray.length-1)>settings.activeImage){objNext=new Image();objNext.src=settings.imageArray[settings.activeImage+1][0];}
if(settings.activeImage>0){objPrev=new Image();objPrev.src=settings.imageArray[settings.activeImage-1][0];}}
function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});}
function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;};function ___pause(ms){var date=new Date();curDate=null;do{var curDate=new Date();}
while(curDate-date<ms);};return this.unbind('click').click(_initialize);};})(jQuery);/**
  Switcher Plugin
  - swaps between 'item' passed in using fade effect
**/
(function($) {

	$.fn.slidingtree=function(options){
		return this.each(function(){			
			if(this._st) return;
			else this._st = plugin_counter;
			var params = $.extend(true, {}, $.fn.slidingtree.defaults, options);
			H[plugin_counter] = {container:this, params:params, items:[]};
			$.slidingtree.setup(plugin_counter);
			plugin_counter ++;

		});
	};
	
	//the default config vars
	$.fn.slidingtree.defaults = { after_function:false, 
	                              active_class:'active', 
	                              end_hide_check_level:"auto", 
	                              node:'li', 
	                              branch:'ul', 
	                              click_trigger:'a', 
	                              speed:'slow'
	                              };
	//the over riden stuff
	$.slidingtree = {
		hash:{}, //the hash used to store all the configs & targets
		/**
     * - loop over everything and give it the right level
     * - hide all but the default level
		 */
		setup:function(index){
		  if(H[index].params.end_hide_check_level == "auto") H[index].params.end_hide_check_level= $.slidingtree.find_depth(index, H[index].container, 0);
		  $.slidingtree.traverse(index,H[index].container, 0, H[index].params.end_hide_check_level);
		  $.slidingtree.triggers(index);
	  },
	  /**
	   * find the depth of the tree and returns the total overall depth -1 (so the leafs at the end are never manipulated by this code)
	   */
	  find_depth:function(index, branch, level){
      H[index].params.end_hide_check_level = level;
      jQ(branch).children(H[index].params.node).each(function(){        
	      jQ(this).children(H[index].params.branch).each(function(){
	        return $.slidingtree.find_depth(index,this,level+1);
	      });	        
	    });
	    return H[index].params.end_hide_check_level -1;
	  },
	  /**
	   * - Loop over the nodes (li) of the branch (ul) passed in
	   * - add node class & level counter on to each leaf thats above the level threshold 
	   *    - the level threshold is used so the end leafs at the lowest level in the tree are never hidden - ie the links to the page
	   * - if the first a it finds does not have a 'active_class' param on it then that branch is hidden 
	   * - if any of this branches(ul) nodes(li) has branchs(ul) then call this function again passing in new level 
	   */
	  traverse:function(index, branch, level, end_level){	
	    jQ(branch).children(H[index].params.node).each(function(){
	      if(!jQ(this).hasClass('node') && level <= H[index].params.end_hide_check_level) jQ(this).addClass('node').addClass('node-'+level);
	      
        if(!jQ(this).find("a:first").hasClass(H[index].params.active_class) && level <= end_level) jQ(this).children(H[index].params.branch).slideUp(H[index].params.speed);
        else jQ(this).children(H[index].params.branch).slideDown(H[index].params.speed);
        jQ(this).find("a:first").attr('rel',level); 
        
	      jQ(this).children(H[index].params.branch).each(function(){
	        return $.slidingtree.traverse(index,this, level+1, end_level);
	      });	        
	    });
	    return;
	  },
	  hide_and_show:function(index){
	    
	  },
	  triggers:function(index){
	    jQ(H[index].container).find(H[index].params.click_trigger).click(function(){
	      // this is a base level item, no sliding, just return true so the page link is followed
        if(!jQ(this).parent().hasClass('node')) return true; 
        else{             
          //find the top node in this tree;
          var current_level = jQ(this).attr('rel'), 
              current_node = jQ(this).parent();                    
          //remove all active classes                 
          jQ(H[index].container).find('.'+H[index].params.active_class).removeClass(H[index].params.active_class);
          //find the right nodes to add active class onto -- so everything above where clicked
          for(var i = current_level; i>=0; i--){
            jQ(current_node).children('a:first').addClass('active');
            if(jQ(current_node).parent().parent().hasClass('node')) current_node = jQ(current_node).parent().parent();
          }
          $.slidingtree.traverse(index,H[index].container, 0, H[index].params.end_hide_check_level+1); //plus one on this so id hides end nodes
        }
      
	      return false;
	    });
	    
	  } 
	  
	};
	var H=$.slidingtree.hash,	jQ = jQuery; ie6=$.browser.msie&&($.browser.version == "6.0"), plugin_counter=0;
})(jQuery);
/**
  Switcher Plugin
  - swaps between 'item' passed in using fade effect
**/
(function($) {

	$.fn.switcher=function(options){
		return this.each(function(){
			if(this._sw) return; //if already a switcher return
			else this._sw = plugin_counter; //otherwise add the index
      var params = $.extend(true, {}, $.fn.switcher.defaults, options);
			H[plugin_counter] = {container:this, params:params,item_switch_countdown:false, switch_function:false,items:[],active:false};
			$.switcher.setup(plugin_counter);
      $.switcher.setup_rotate(plugin_counter);
			if(H[plugin_counter].params.pagination) $.switcher.pagination_trigger(plugin_counter);
			plugin_counter ++;
		});
	};

	//the default config vars
	$.fn.switcher.defaults = {after_function:false, auto_rotate:false, rotate_time:6000, item:'.item', pagination:false, pagination_active_class:'active' ,speed:"slow", swap_container_class:false};
	//the over riden stuff
	$.switcher = {
		hash:{}, //the hash used to store all the configs & targets
		/*
		 loop over all items in the container and add new class and also push them to the internal array - this
		 is then used for rotate / pagination etc
		*/
		setup:function(index){
		  var counter = 0;
			H[index].switch_function = function(){$.switcher.rotate(index);};
      jQ(H[index].container).find(H[index].params.item).each(function(){
        H[index].items.push(this);
        jQ(this).addClass('switcher').addClass('switcher_'+counter);
        if(counter>0) jQ(this).hide();
        counter++;
      });
      H[index].active = 0;
	  },
	  setup_rotate:function(index){
			if(H[index].item_switch_countdown) clearTimeout(H[index].item_switch_countdown);
	    if(H[index].params.auto_rotate && H[index].params.rotate_time){
		 		H[index].item_switch_countdown = setTimeout(H[index].switch_function, H[index].params.rotate_time);
      }
	  },
	  rotate:function(index){
	    var outbound = 0;
      if(!H[index].active) H[index].active = outbound = 0;
      else outbound = H[index].active;
      var inbound=parseInt(outbound) +1;
			if(inbound > H[index].items.length-1) inbound = 0; //so doesnt rotate beyond limits!
      $.switcher.hide_show(index,outbound, inbound);
	  },
	  hide_show:function(index,outbound,inbound){			
	    jQ(H[index].items[outbound]).fadeOut(H[index].params.speed, function(){
        jQ(H[index].items[inbound]).fadeIn(H[index].params.speed, function(){
          if(H[index].params.after_function) H[index].params.after_function();
        });
        if(H[index].params.swap_container_class){
          var class_name = jQ(H[index].items[inbound]).find("h2 a").attr('rel');
          jQ(H[index].container).attr('class', class_name);
        }
        if(H[index].params.pagination){
          var target_href = '#'+jQ(H[index].items[inbound]).attr('id');
          jQ(H[index].container).find('.'+H[index].params.pagination_active_class).removeClass(H[index].params.pagination_active_class);
          jQ(H[index].container).find('a[href='+target_href+']').parent().addClass(H[index].params.pagination_active_class);
        }
	      $.switcher.setup_rotate(index);
      });
      H[index].active = inbound;
	  },
	  pagination_trigger:function(index){
	    var search_for = '#'+H[index].container.id+' '+H[index].params.pagination+' a';
	    jQ(search_for).hover(function(){
	      //clear timers
	      var match_to = this.rel.replace('#', ''), inbound = 0;
        for(var i in H[index].items){
          if(jQ(H[index].items[i]).attr('id') == match_to) inbound = i;
        }

	      $.switcher.hide_show(index, H[index].active, inbound);
	      return false;
	    },function(){
				$.switcher.setup_rotate(index);
				return false;
			});
			jQ(search_for).click(function(){return false;});
	  }
	};
	var H=$.switcher.hash,	jQ = jQuery; ie6=$.browser.msie&&($.browser.version == "6.0"), plugin_counter=0;
})(jQuery);
/* -------------------------------------------------- *
 * JQuery Hints
 * -------------------------------------------------- *
 * Author: Ross Riley
 * License: MIT License
** -------------------------------------------------- */

(function($) {
	$.fn.hint = function(defaults) {
		// check whether we want real options, or to destroy functionality
		if(!defaults || typeof(defaults) == "object") {
			defaults = $.extend({
				focus_class: "hint_focus", // class during focus
				changed_class: "hint_changed", // class after focus
				populate_from: "default", // choose from: default, label, custom, or alt
				text: null, // text to use in conjunction with populate_from: custom
				remove_labels: false // remove labels associated with the fields
			}, defaults);
		}
		else if(typeof(defaults) == "string" && defaults.toLowerCase() == "destroy") {
			var destroy = true;
		}
		return this.each(function() {
			// unbind everything if we're destroying, and stop executing the script
			if(destroy) {
			  $(this).unbind("focus.hint").unbind("blur.hint").removeData("defText");
				return false;
			}
		  hint_setup($(this));
		});
	  function hint_setup(ele){ 
	    // define our variables
			var defText = "";

			// let's populate the text, if not default
			switch(defaults.populate_from) {
				case "alt":
					defText = ele.attr("alt");
					ele.val(defText);
					break;
				case "label":
					defText = $("label[for='" + ele.attr("id") + "']").text();
					ele.val(defText);
					break;
				case "custom":
					defText = defaults.text;
					ele.val(defText);
					break;
				default:
					defText = ele.val();
			}

			// let's give this field a special class, so we can identify it later
			// also, we'll give it a data attribute, which will help jQuery remember what the default value is
			ele.addClass("hint").data("defText", defText);

			// now that fields are populated, let's remove the labels if applicable
			if(defaults.remove_labels == true) { $("label[for='" + ele.attr("id") + "']").remove(); }
			
			// Handles password fields by creating a clone that's a text field.
			if(ele.attr("type")=="password") {
			  var eledef = ele.data("defText");
			  var el = ele.clone().data("defType", "password").data("defText", eledef).attr("type", "text");
        ele.after(el).remove();
        var ele = el;
		  }
			hint_focus(ele);
			hint_blur(ele);
	  };
	  function hint_focus(ele){ 
	    ele.bind("focus.hint",function(){
	      if(ele.val() == ele.data("defText")) { ele.val(""); }
				// add the focus class, remove changed_class
				ele.addClass(defaults.focus_class).removeClass(defaults.changed_class);
	      if(ele.data("defType")=="password") {
	        var eledef = ele.data("defText");
  			  var el = ele.clone().data("defText", eledef).data("defType","password").attr("type", "password");
          ele.after(el).remove();
          hint_blur(el);
          el.eq(0).focus();
  			}
			});
	  };
	  function hint_blur(ele){ 
	    ele.bind("blur.hint",function(){
	      if(ele.val() == "") { ele.val(ele.data("defText")); }
				// remove focus_class, add changed_class.
				ele.removeClass(defaults.focus_class);
				if(ele.val() != ele.data("defText")) { ele.addClass(defaults.changed_class); }
					else { ele.removeClass(defaults.changed_class); }
				if(ele.data("defType")=="password" && ele.val()==ele.data("defText")) {
				  var eledef = ele.data("defText");
				  var el = ele.clone().data("defText", eledef).data("defType", "password").attr("type", "text");
          ele.after(el);
          ele.remove();
          hint_focus(el);
				}
	    });
	  };
	};
})(jQuery);/*
ClockPick, by Josh Nathanson
Version 1.2.7
Timepicker plugin for jQuery
See copyright at end of file
Complete documentation at http://www.jnathanson.com/index.cfm?page=jquery/clockpick/ClockPick
name	 clockpick
type	 jQuery
param	 options                  hash                    object containing config options
param	 options[starthour]       int                     starting hour (use military int)
param	 options[endhour]         int                     ending hour (use military int)
param	 options[showminutes]     bool                    show minutes
param 	 options[minutedivisions] int                     number of divisions, i.e. 4 = :00, :15, :30, :45
param 	 options[military]        bool                    use 24hr time if true
param	 options[event]           string                  mouse event to trigger plugin
param	 options[layout]          string                  set div layout to vertical or horizontal
                                  ('vertical','horizontal')
param	 options[valuefield]      string                  field to insert time value, if not same as click field
                                  (name of input field)
param	 options[useBgiframe]	  bool					  set true if using bgIframe plugin
param	 options[hoursopacity]	  float					  set opacity of hours container
param 	 options[minutesopacity]  float					  set opacity of minutes container
param	 callback                 function                callback function - gets passed back the time value as a 
														  string
*/

jQuery.fn.clockpick = function(options, callback) {

	var settings = {
		starthour       : 8,
		endhour         : 18,
		showminutes     : true,
		minutedivisions : 4,
		military        : false,
		event           : 'click',
		layout			: 'vertical',
		valuefield		: null,
		useBgiframe		: false,
		hoursopacity	: 1,
		minutesopacity  : 1
		};
		
	if(options) {
		jQuery.extend(settings, options);
	};
	
	var callback = callback || function() { },
	 	v = (settings.layout == 'vertical'); // boolean for vertical, shorten footprint
	errorcheck();	
	
	jQuery(this)[settings.event](function(e) {
		
		var self = this,
		$self = jQuery( this ),
		$body = jQuery( "body" );
		
		if ( !settings.valuefield ) {
			$self.unbind( "keydown" ).bind( "keydown", keyhandler );
		}
		else {
			var inputfield = jQuery("[name=" + settings.valuefield + "]");
			inputfield
				.unbind( "keydown" )
				.bind( "keydown", keyhandler)[0]
				.focus();
			inputfield
				.bind("click", function() { inputfield.unbind("keydown"); } );										
		}
		// clear any malingerers
		jQuery("#CP_hourcont,#CP_minutecont").remove();
		
		// append hourcont to body
		// add class "CP" for mouseout recognition, although there is only
		// one hourcont on the screen at a time
		$hourcont = jQuery("<div id='CP_hourcont' class='CP' />").appendTo( $body );
		!settings.useBgiframe ? $hourcont.css("opacity",settings.hoursopacity) : null;
		binder( $hourcont );
		
		$hourcol1 = jQuery("<div class='CP_hourcol' id='hourcol1' />").appendTo( $body );
		$hourcol2 = jQuery("<div class='CP_hourcol' id='hourcol2' />").appendTo( $body );

		// if showminutes, append minutes cont to body
		if (settings.showminutes) {
			$mc = jQuery("<div id='CP_minutecont' class='CP' />").appendTo( $body );
			!settings.useBgiframe ? $mc.css("opacity",settings.minutesopacity) : null;
			binder($mc);
		}
		if ( !v ) {
			$hourcont.css("width","auto");
			$mc.css("width","auto");
		}
		else {
			$hourcol1.addClass('floatleft');
			$hourcol2.addClass('floatleft');
		}
				
		// all the action right here
		// fill in the hours container (minutes rendered in hour mouseover)
		// then make hour container visible
		renderhours();
		putcontainer();
		
		/*----------------------helper functions below-------------------------*/
				
		function renderhours() {
			// fill in the $hourcont div
			var c = 1; 
			// counter as index 2 of hr id, gives us index 
			// in group of hourdivs for calculating where to put minutecont on keydown
			for (h=settings.starthour; h<=settings.endhour; h++) {
				
				if(h==12) { c = 1; } // reset counter for col 2
				
				displayhours = ((!settings.military && h > 12) ? h - 12 : h);
				// rectify zero hour
				if (!settings.military && h == 0) {
					displayhours = '12';
				}
				if ( settings.military && h < 10 ) {
					displayhours = '0' + displayhours;
				}
				$hd = jQuery("<div class='CP_hour' id='hr_" + h + "_" + c + "'>" + displayhours + set_tt(h) + "</div>");
				// shrink width a bit if military
				if (settings.military) { $hd.width(20); }
				binder($hd);
				if (!v) {
					$hd.css("float","left");
				}
				(h<12) ? $hourcol1.append($hd) : $hourcol2.append($hd);
				c++;
			}
			$hourcont.append($hourcol1);
			!v ? $hourcont.append("<div style='clear:left' />") : '';
			$hourcont.append($hourcol2);
		}
		
		function renderminutes(h) {
			realhours = h;
			displayhours = (!settings.military && h > 12) ? h - 12 : h;
			if (!settings.military && h == 0) {
				displayhours = '12';
			}
			if ( settings.military && h < 10 ) {
				displayhours = '0' + displayhours;
			}
			$mc.empty();
			var n = 60 / settings.minutedivisions,
				tt = set_tt(realhours),
				counter = 1;
		
			for(m=0;m<60;m=m+n) {
				$md = jQuery("<div class='CP_minute' id='" + realhours + "_" + m + "'>" 
							 + displayhours + ":" + ((m<10) ? "0" : "") + m + tt 
							 + "</div>");
				if ( !v ) {
					$md.css("float","left");
					if (settings.minutedivisions > 6 
						&& counter == settings.minutedivisions / 2 + 1) {
						// long horizontal, kick in extra row after half
						$mc.append("<div style='clear:left' />");
					}
				}
				$mc.append($md);
				binder($md);
				counter++;
			}
		}
		
		function set_tt(realhours) {
			if (!settings.military) { 
				return (realhours >= 12) ? ' PM' : ' AM'; 
				}
			else { 
				return '';
			}
		}
		
		function putcontainer() {
			if ( e.type != 'focus') {
				$hourcont
				.css("left",e.pageX - 5 + 'px')
				.css("top",e.pageY - (Math.floor($hourcont.height() / 2)) + 'px');
				rectify($hourcont);
			}
			else {
				$self.after($hourcont);
			}
			$hourcont.slideDown('fast');
			
			if ( settings.useBgiframe )
				bgi( $hourcont );			
		}
		
		function rectify($obj) { 
			// if a div is off the screen, move it accordingly
			var ph = document.documentElement.clientHeight 
						? document.documentElement.clientHeight 
						: document.body.clientHeight;
			var pw = document.documentElement.clientWidth
						? document.documentElement.clientWidth
						: document.body.clientWidth;
			var t = parseInt($obj.css("top"));
			var l = parseInt($obj.css("left"));
			var st = document.documentElement.scrollTop 
						? document.documentElement.scrollTop 
						: document.body.scrollTop;
			// run off top
			if ( t <= st && !$obj.is("#CP_minutecont") ) {
				$obj.css("top",st+10+'px');
			}
			else if (t + $obj.height() - st > ph) {
				$obj.css("top",st + ph - $obj.height() - 10 + 'px');
			}
			if ( l <= 0 ) {
				$obj.css("left", '10px');
			}
		}
		
		function bgi( ob ) {
			if ( typeof jQuery.fn.bgIframe == 'function' )
				ob.bgIframe();
			else
				alert('bgIframe plugin not loaded.');
		}
		
		function binder($obj) {
		// all the binding is done here
		// event handlers have been abstracted out,
		// so they can handle mouse or key events
		
			// bindings for hc (hours container)
			if($obj.attr("id") == 'CP_hourcont') {
				$obj.mouseout(function(e) { hourcont_out(e) });
			}
			
			// bindings for mc (minute container)
			else if ($obj.attr("id") == 'CP_minutecont') {
				$obj.mouseout(function(e) { minutecont_out(e) });
			}
			
			// bindings for $hd (hour divs)
			else if ($obj.attr("class") == 'CP_hour') {
				$obj.mouseover(function(e) { hourdiv_over($obj, e) });
				$obj.mouseout(function() { hourdiv_out($obj) });					
				$obj.click(function() {	hourdiv_click($obj) });
			}
			
			// bindings for $md (minute divs)
			else if ($obj.attr("class") == 'CP_minute') {
				$obj.mouseover(function() { minutediv_over($obj) });
				$obj.mouseout(function() { minutediv_out($obj) });					
				$obj.click(function() {	minutediv_click($obj) });
			}
		};
		
		function hourcont_out(e) {
			/*
			this tells divs to clear only if rolling all the way 
			out of hourcont.
			relatedTarget "looks ahead" to see where the mouse
			has moved to on mouseOut.
			IE uses the more sensible "toElement".
			try/catch for Mozilla bug on relatedTarget-input field.
			*/
			try {
				t = (e.toElement) ? e.toElement : e.relatedTarget;
				if (!(jQuery(t).is("div[class^=CP], iframe"))) {
					// Safari incorrect mouseover/mouseout
					//if (!jQuery.browser.safari) {
						cleardivs();
					//}
				}	
			}
			catch(e) {
				cleardivs();
			}
		}
		
		function minutecont_out(e) {
			try {
				t = (e.toElement) ? e.toElement : e.relatedTarget;
				if (!(jQuery(t).is("div[class^=CP], iframe"))) {
					cleardivs();
				}		
			}
			catch(e) {
				cleardivs();
			}
		}
		
		function hourdiv_over($obj, e) {
			var h = $obj.attr("id").split('_')[1],
				i = $obj.attr("id").split('_')[2],
				l,
				t;
			$obj.addClass("CP_over");
			if ( settings.showminutes ) {
				$mc.hide();
				renderminutes(h);
				
				// set position & show minutes container
				if (v) {
					t = e.type == 'mouseover'
						? e.pageY - 15
						: $hourcont.offset().top + 2 + ($obj.height() * i);
					if ( h < 12 )
						l = $hourcont.offset().left - $mc.width() - 2;
					else
						l = $hourcont.offset().left + $hourcont.width() + 2;
				}
				else {
					l = (e.type == 'mouseover') 
						? e.pageX - 10 
						: $hourcont.offset().left + ($obj.width()-5) * i;
					if(h<12) {
						t = $hourcont.offset().top - $mc.height() - 2;
					}
					else {
						t = $hourcont.offset().top + $hourcont.height();
					}
				}
				$mc.css("left",l+'px').css("top",t+'px');
				rectify( $mc );
				$mc.show();
				
				if ( settings.useBgiframe )
					bgi( $mc );
			}
			return false;
		}
		
		
		
		function hourdiv_out($obj) {
			$obj.removeClass("CP_over");
			return false;
		}
		
		function hourdiv_click($obj) {
			h = $obj.attr("id").split('_')[1];
			tt = set_tt(h);
			str = $obj.text();
			if(str.indexOf(' ') != -1) {
				cleanstr = str.substring(0,str.indexOf(' '));
			}
			else {
				cleanstr = str;
			}
			$obj.text(cleanstr + ':00' + tt);
			setval($obj);
			cleardivs();
		}
		
		function minutediv_over($obj) {
			$obj.addClass("CP_over");
			return false;
		}
		
		function minutediv_out($obj) {
			$obj.removeClass("CP_over");	
			return false;
		}
		
		function minutediv_click($obj) {
			setval($obj);
			cleardivs();
		}
		
		function setval($obj) { // takes either hour or minute obj
			if(!settings.valuefield) {
				self.value = $obj.text();
			}
			else {
				jQuery("input[name=" + settings.valuefield + "]").val($obj.text());
			}
			callback.apply( $self, [ $obj.text() ]);
			// unbind keydown handler, otherwise it will double-bind if 
			// field is activated more than once
			$self.unbind( "keydown", keyhandler );
		}
		
		function cleardivs() {
			if (settings.showminutes) {
				$mc.hide();
			}
			$hourcont.slideUp('fast');
			$self.unbind( "keydown", keyhandler );
		}
		
		// keyboard handling
		
		function keyhandler( e ) {
			
			// $obj is current active div
			var $obj = $("div.CP_over").size() ? $("div.CP_over") : $("div.CP_hour:first"),
				divtype = $obj.is(".CP_hour") ? 'hour' : 'minute',
				hi = (divtype == 'hour') ? $obj[0].id.split('_')[2] : 0, // hour index
				h = (divtype == 'minute') ? $obj[0].id.split('_')[0] : $obj[0].id.split('_')[1]; // real hour 
			if (divtype == 'minute') 
				{ var curloc = h<12 ? 'm1' : 'm2' }
			else 
				{ var curloc = h<12 ? 'h1' : 'h2' }
			
			function divprev($obj) {
				if ($obj.prev().size()) {
					eval(divtype + 'div_out($obj)');
					eval(divtype + 'div_over($obj.prev(), e)');
				}
				else { return false; }
			}
			
			function divnext($obj) {
				if ($obj.next().size()) {
					eval(divtype + 'div_out($obj)');
					eval(divtype + 'div_over($obj.next(), e)');
				}
				else { return false; }
			}
			
			function hourtohour($obj) {
				var ctx = h>=12 ? '#hourcol1' : '#hourcol2';
				$newobj = jQuery(".CP_hour[id$=_" + hi + "]", ctx );
				if ($newobj.size()) {
					hourdiv_out($obj);
					hourdiv_over($newobj, e);
				}
				else { return false; }
			}
			
			function hourtominute($obj) {
				hourdiv_out($obj);
				minutediv_over($(".CP_minute:first"));
			}
			
			function minutetohour($obj) {
				minutediv_out($obj);
				var ctx = h>=12 ? '#hourcol2' : '#hourcol1';
				// extract hour from minutediv, then find hourdiv with that hour
				var $newobj = jQuery(".CP_hour[id^=hr_" + h + "]", ctx);
				hourdiv_over($newobj, e);
			}

			switch (e.keyCode) {
				case 37: // left arrow
					if (v) {
						switch (curloc) {
							case 'm1':
								return false;
								break;
							case 'm2':
								minutetohour($obj);
								break;
							case 'h1':
								hourtominute($obj);
								break;
							case 'h2':
								hourtohour($obj);
								break;
						}
					}
					else {
						divprev($obj);
					}
					break;
					
				case 38: // up arrow
					if(v) {
						divprev($obj);
					}
					else {
						switch (curloc) {
							case 'm1':
								return false;
								break;
							case 'm2':
								minutetohour($obj);
								break;
							case 'h1':
								hourtominute($obj);
								break;
							case 'h2':
								hourtohour($obj);
								break;
						}
					}
					break;
				case 39: // right arrow
					if (v) {
						switch (curloc) {
							case 'm1':
								minutetohour($obj);
								break;
							case 'm2':
								return false;
								break;
							case 'h1':
								hourtohour($obj);
								break;
							case 'h2':
								hourtominute($obj);
								break;
						}
					}
					else {
						divnext($obj);
					}
					break;
				
				case 40: // down arrow
					if(v) {
						divnext($obj);
					}
					else {
						switch (curloc) {
							case 'm1':
								minutetohour($obj);
								break;
							case 'm2':
								return false;
								break;
							case 'h1':
								hourtohour($obj);
								break;
							case 'h2':
								hourtominute($obj);
								break;
						}
					}
					break;
					
				case 13: // return
					eval(divtype + 'div_click($obj)');
					break;
					
				default:
					return true;
			}
					
		return false;
			
		}

	return false;
	});
	
	function errorcheck() {
		if (settings.starthour >= settings.endhour) {
			alert('Error - start hour must be less than end hour.');
			return false;
		}
		else if (60 % settings.minutedivisions != 0) {
			alert('Error - param minutedivisions must divide evenly into 60.');
			return false;
		}
	}
	
	return this;

}

/*
+-----------------------------------------------------------------------+
| Copyright (c) 2007 Josh Nathanson                  |
| All rights reserved.                                                  |
|                                                                       |
| Redistribution and use in source and binary forms, with or without    |
| modification, are permitted provided that the following conditions    |
| are met:                                                              |
|                                                                       |
| o Redistributions of source code must retain the above copyright      |
|   notice, this list of conditions and the following disclaimer.       |
| o Redistributions in binary form must reproduce the above copyright   |
|   notice, this list of conditions and the following disclaimer in the |
|   documentation and/or other materials provided with the distribution.|
|                                                                       |
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
|                                                                       |
+-----------------------------------------------------------------------+
*/