$(document).ready(function(){

	// Fancyboxise iframe links
    $('a.iframe').fancybox({
        type      : 'iframe',
        width     :   600,
        height    :   500,
        titleShow : false
    });
    
    // Fancyboxise links for the 2010 DVD
    $('a[href="/video/dvd2010"]').fancybox({
        type      : 'iframe',
        width     :   800,
        height    :   650,
        titleShow : false
    });

    // Fancyboxise awards results page flippers
    $('a.awardsResultsBrochure').fancybox({
        type      : 'iframe',
        width     :   1020,
        height    :   730,
        titleShow : false
    });
    
    // Make report galleries
    $('ul.gallery').galleria({
    	onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
					
			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.6);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.6';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.6); } // don't fade out if the parent is active
			)
		}

	}); 

});



function awardsEntryForm()
{
	
	var awardsEntrySelectListener = function (){
		
		var freeMessage;
		var topMessage;
		var categoryId = $('#awards_entry_awards_category_id').val();
		
		$('#awardsCategoryDetails div').hide();
		$('#category' + categoryId).show();
		
		// Remove labels and hide the free row
		$('#GPDMlabel').remove();
		$('#freeMessage').remove();
		$('#awards_entry_free').parents('tr').hide();
		
		// Handle 3. JAC 
		if(categoryId == 5)
		{
			freeMessage = "Select this for free entry in the campaign award if you have entered at least three components in any main HCP press category";
		}
		
		// 5. Primary care direct mail
		if(categoryId == 7)
		{
			topMessage = 'Entering this award entitles you to a free entry in the HCP Direct Mail Award, add this again as a separate entry and check the free box for that entry';
		}
		
		// 6. HCP direct mail
		if(categoryId == 8)
		{
			freeMessage = 'Check this for free entry in this category if you have entered the same work into the Primary Care Direct Mail category';
		}
		
		// Handle 3. JAC or 6. HCP DM
		if((categoryId == 5)||(categoryId == 8))
		{
			$('#awards_entry_free').after('<label for="awards_entry_free" id="freeMessage">' + freeMessage + '</label>');
			$('#awards_entry_free').parents('tr').show();		
		}
		
		if(topMessage)
		{
			$('#awards_entry_awards_category_id').after('<div id="GPDMlabel">' + topMessage + '</div>');
		}
	}
	
	/* register listener for change of category select */
	$('#awards_entry_awards_category_id').change(awardsEntrySelectListener).keyup(awardsEntrySelectListener);
	
	awardsEntrySelectListener();
}


