jQuery(function($) {
	jQuery("body").addClass("jsEnabled");
	
	// Make legends into H2s for easier styling, while maintaining semantic markup.
	jQuery("legend").each(function(){
		var $this = jQuery(this); 
		var legendText = $this.text();
		$this.parent("fieldset")
			.before("<h2>" + legendText + "</h2>")
			.end()
			.remove();
	});
	
	//E-card Gallery
	jQuery("#ecardGalleryInner").scrollable({
		items: '#gallery-items',
		speed: 250,
		size: 5,
		clickable: false,
		keyboard: false,
		next: '.nextImage',
		prev: '.prevImage'
	});
	
		/* To change image on click */
		jQuery("#gallery-items div img").click(function(){
			var imageSrc = jQuery(this).attr("src");
			var imageSrc = imageSrc.replace(/ecards-thumbnail\//, "");
			
			jQuery("#ecardImage img").attr("src", imageSrc);
			jQuery("#imageSrc input").val(imageSrc);
		});
	
	//Lightbox script
	jQuery("a[rel^='lightbox']").prettyPhoto({
		theme: 'light_rounded',
		showTitle: false,
		opacity: 0.5
	});
			
	// Adding hover in IE for non-anchor elements
	jQuery(".hoverEnabled").hover(
		function() {
			jQuery(this).addClass("hover");
		},
		function(){
			jQuery(this).removeClass("hover");
		}
	);
	
	//Open PDFs in a different window
	$('a').each(function(){
		if( $(this).attr('href') != "" ) {
			var href = $(this).attr('href');
			if(href.indexOf('.pdf') != -1){
				$(this).click(function(){
					window.open(this.href);
					return false;
				});
			}
		} else {
			return false;
		}
	});
	
	//Opens external pages in a new window
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank");  
	$("a[href*='https://']:not([href*='"+location.hostname+"'])").attr("target","_blank");  
	
	//Add zebra-striping to tables
	if( !jQuery("table").hasClass("jscalendar-DB-table-style") ) {
		jQuery("table tr:odd").addClass("odd");
	}
	
	//Allows for styling on focus/blur input fields
	jQuery('input[type="text"]').focus(function(){
		jQuery(this).select().addClass("focused");
	});
	jQuery('input[type="text"]').blur(function(){
		jQuery(this).removeClass("focused");
	});
	
}); 

