(function($) {
	$(function() {
		
		$('li.dropdown').hover(function(){
			$(this).addClass('hover').children('a:first').addClass('dropdown-hover');
		},function(){
			$(this).removeClass('hover').children('a:first').removeClass('dropdown-hover');
		});
		
		if ($('.tabs').length > 0) {
			$.getScript('/mysite/javascript/jquery.simpleTabs.js',function(){
				$('.tabs').simpleTabs();
			});
		}
		
		if ($('.toggle-holder').length > 0) {
			$.getScript('/mysite/javascript/jquery.contentToggle.1.0.js',function(){
				$('.toggle-holder').contentToggle({ startClosed:true, controls:true });
			});
		}
		
		if ($('#Form_SiteSearchForm_SiteID').length > 0) {
			$.getScript('/epr/javascript/search.js');
		}
		
		if ($('[rel^=shadowbox]').length > 0) {
			$.getScript('/mysite/javascript/shadowbox-3.0.3/shadowbox.js',function(){
				$('head').append('<link rel="stylesheet" type="text/css" media="screen" href="mysite/javascript/shadowbox-3.0.3/shadowbox.css" />');
				Shadowbox.init();
			});
		}
		
		if ($('map').length > 0 && !$('#epr_map').length) {
			$.getScript('/mysite/javascript/jquery.qtip/jquery.qtip-custom.min.js',function(){
				$('head').append('<link rel="stylesheet" type="text/css" media="screen" href="mysite/javascript/jquery.qtip/jquery.qtip.css" />');
				$('map area').each(function(){
				
					alt = $(this).attr('alt');
					$(this).qtip({
						content: alt,
						style: {
							classes: 'imagetip',
							tip: {
								corner: true,
								width: 12,
								height: 12,
								border: 1
							}
						},
						position: {
							my: 'top left',
							at: 'bottom left',
							adjust: {
								x: 0, y: 0,
								screen: 'flip'
							}
						}
					});
				
				}).click(function(){ return false; });
			});
		}
		
		/* FANCYBOX IMAGE GALLERY/POPUPS */
		if ($('a[rel=gallery],a[href$=.jpg],a[href$=.png],a[href$=.gif]').length > 0) {
			$.getScript('mysite/javascript/fancybox/jquery.fancybox-1.3.4.pack.js', function() {
				$.getScript('mysite/javascript/fancybox/jquery.easing-1.3.pack.js');
				$('head').append('<link rel="stylesheet" type="text/css" media="screen" href="mysite/javascript/fancybox/jquery.fancybox-1.3.4.css" />');
				
				$('a.first').click(function(){
					$('a.second').removeAttr('rel');
				});
				
				$('a.second').click(function(){
					$('a.first').removeAttr('rel');
				});
				
				$('a[rel=gallery],a[href$=.jpg],a[href$=.png],a[href$=.gif]').fancybox({
					padding: 10,
					margin: 20,
					cyclic: true,
					autoScale: true,
					autoDimensions: true,
					centerOnScroll: true,
					titlePosition: 'over',
					transitionIn: 'elastic',
					showCloseButton: true,
					onClosed: function() {
						$('.slides a.first').attr('rel', 'gallery');
						$('.slides a.second').attr('rel', 'gallery');
					}
				});
			});
		}
		
		if ($('.slider').length > 0) {
			$('head').append('<link rel="stylesheet" href="mysite/css/nivo-slider.css" type="text/css" />');
			$.getScript('mysite/javascript/aer.nivo.slider.js',function(){
				$('.slider').nivoSlider({
					slices:1,
					effect:'fade',
					animSpeed:500,
					manualAdvance:false,
					pauseTime: 8000,
					directionNav:false,
					controlNav:true,
					captionOpacity:1

				});
			});
		}
		
	});
})(jQuery);
