var grilledcheese = { src: '/assets/swf/grilled-cheese.swf' };

sIFR.wmode = 'transparent';

sIFR.activate(grilledcheese);

sIFR.replace(grilledcheese, {
  selector: '#interior.kids h2',
  css:
  [
  	'.sIFR-root { background-color: transparent; color: #864F1B; }', 
  	'a { text-decoration: none, color: ‘#4A2E0E′ }',
	'a:link { color: #4A2E0E; }',
  	'a:hover { color: ‘#8E6739’ }'
  ],
  wmode: 'transparent'
});

sIFR.replace(grilledcheese, {
  selector: '#interior.kids h3.home-message',
  css: '.sIFR-root { background-color: transparent; color: #25AB50; }',
  wmode: 'transparent'
});

sIFR.replace(grilledcheese, {
  selector: '#body h4',
  css:
  [
  	'.sIFR-root { background-color: transparent; color: #864F1B; }', 
  	'a { text-decoration: none, color: ‘#4A2E0E′ }',
	'a:link { color: #4A2E0E; }',
  	'a:hover { color: ‘#8E6739’ }'
  ],
  wmode: 'transparent'
});

$(document).ready(function () {

	$('.lightbox').lightBox();
	
	if ( document.getElementById('slideshow') ) {
		var flashvars_slideshow = {};
		var params_slideshow = {
			base: ".",
			allowfullscreen: "true"
		};
		var attributes_slideshow = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/fota-gallery-ssp.swf", "slideshow", "550", "400", "9.0.0", false, flashvars_slideshow, params_slideshow, attributes_slideshow);
	}
	
	if ( document.getElementById('art-gallery-slideshow') ) {
		var flashvars_art = {};
		var params_art = {
			base: ".",
			allowfullscreen: "true"
		};
		var attributes_art = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/fota-art-ssp.swf", "art-gallery-slideshow", "550", "400", "9.0.0", false, flashvars_art, params_art, attributes_art);
	}
	
	if ( document.getElementById('babies-gallery-slideshow') ) {
		var flashvars_babies = {};
		var params_babies = {
			base: ".",
			allowfullscreen: "true"
		};
		var attributes_babies = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/fota-babies-ssp.swf", "babies-gallery-slideshow", "550", "400", "9.0.0", false, flashvars_babies, params_babies, attributes_babies);
	}
	
	/** GAMES **/
	if ( document.getElementById('game-puzzle') ) {
		var flashvars_puzzle = {};
		var params_puzzle = {
			base: ".",
			allowfullscreen: "true",
			wmode: "transparent"
		};
		var attributes_puzzle = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/games/puzzle/puzzle.swf", "game-puzzle", "550", "400", "9.0.0", false, flashvars_puzzle, params_puzzle, attributes_puzzle);
	}
	
	if ( document.getElementById('fox-puzzle') ) {
		var flashvars_fox_puzzle = {};
		var params_fox_puzzle = {
			base: ".",
			allowfullscreen: "true",
			wmode: "transparent"
		};
		var attributes_fox_puzzle = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/games/fox-puzzle/universal_puzzle.swf", "fox-puzzle", "550", "400", "9.0.0", false, flashvars_fox_puzzle, params_fox_puzzle, attributes_fox_puzzle);
	}
	
	if ( document.getElementById('animal-quiz') ) {
		var flashvars_animal_quiz = {};
		var params_animal_quiz = {
			base: ".",
			allowfullscreen: "true",
			wmode: "transparent"
		};
		var attributes_animal_quiz = {};
		swfobject.embedSWF("http://www.fotawildlife.ie/assets/swf/games/animal-quiz/soQuiz08.swf", "animal-quiz", "550", "400", "9.0.0", false, flashvars_animal_quiz, params_animal_quiz, attributes_animal_quiz);
	}
	


	$('#cal-prev').live('click', function()
	{
		$.ajax({
			url: 		'/ajax/calendar'+this.getAttribute('rel'),
			dataType: 	'html',
			success: 	function(html){
				$('#calendar .side-box-content').empty().append(html);
			}		
		});
		return false;
	});
	
	$('#cal-next').live('click', function()
	{
		$.ajax({
			url: 		'/ajax/calendar'+this.getAttribute('rel'),
			dataType: 	'html',
			success: 	function(html){
				$('#calendar .side-box-content').empty().append(html);
			}		
		});
		return false;
	});
	
	$("a.event").live("mouseover", function(){
   		$(this).qtip({
   			show: { ready: true },
   			content: $(this).attr('rel'), 
   			style: { name: 'green', tip: true },
		   	position: {
		      corner: {
		         target: 'leftTop',
		         tooltip: 'bottomLeft'
		      }
		   }
   		});
	});
	
	
	// Check cookie for side-menu div status
	$("#side .side-box").each(function(e)
	{
		var div_id = $(this).attr('id');
		var cookie = $.cookie(div_id+'-status');
		
		if ( cookie ) {
			if ( cookie == 'show' ) {
				$('#' + div_id + ' .side-box-content').show();
				$('#' + div_id + ' h3 .toggle').addClass('hide');
			} else if ( cookie == 'hide' ) {
				$('#' + div_id + ' .side-box-content').hide();
				$('#' + div_id + ' h3 .toggle').addClass('show');
			}
		}
	
	});
	
	// Toggle side-menu divs
	$(".side-box h3 .toggle").click(function()
	{
		$(this).parent().next(".side-box-content").slideToggle("slow", function()
		{
			var div_id = $(this).parent().attr('id');
			
			if ( $(this).is(':visible') ) {
            	$.cookie(div_id+'-status', 'show', {expires: 30, domain: 'fotawildlife.ie'});
            	$(this).prev().children('a.toggle').addClass('hide');
            	$(this).prev().children('a.toggle').removeClass('show');
            } else {
            	$.cookie(div_id+'-status', 'hide', {expires: 30, domain: 'fotawildlife.ie'});
            	$(this).prev().children('a.toggle').addClass('show');
            	$(this).prev().children('a.toggle').removeClass('hide');
            }
		});
		return false;
	});
	
	if ( document.getElementById('field_id_27') )
	{
		$("#field_id_27").charCounter(600, {format: "600 characters max. %1/600 remaining", softcount: false, container: '<div></div>'});
	}
	
	if ( document.getElementById('guestbook-form-subject') ) 
	{
		$("#guestbook-form-subject #title").charCounter(50, {format: "50 characters max. %1/50 remaining", softcount: false, container: '<div></div>'});
	}
		
	if ( $("input.datepicker").length > 0 ) {
		date_obj = new Date();
		date_obj_hours = date_obj.getHours();
		date_obj_mins = date_obj.getMinutes();
		
		if (date_obj_mins < 10) { date_obj_mins = "0" + date_obj_mins; }
		
		if (date_obj_hours > 11) {
		    date_obj_hours = date_obj_hours - 12;
		    date_obj_am_pm = " PM";
		} else {
		    date_obj_am_pm = " AM";
		}
		
		date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+date_obj_am_pm+"'";
		
		$(".datepicker").datepicker({showButtonPanel: true, dateFormat: $.datepicker.W3C +' '+ date_obj_time});

	}
	
	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

	
	if ( document.getElementById('animal-list') )
	{
		var divViewOptionsTop = $('<div>').attr('id','dyn-view-options-top');
		//var divViewOptionsBottom = $('<div>').attr('id','dyn-view-options-bottom');
		
		$(divViewOptionsTop).append($("<a>").attr('href','#').attr('id','dyn-list-view').attr('class', 'active').text('List View').click(
		function()
		{
			$('#animal-grid').hide();
			$('#dyn-grid-view').removeClass('active');
			$('#dyn-list-view').attr('class', 'active');
			$('#animal-list_wrapper').show();
			return false;
		}));
		$(divViewOptionsTop).append($("<a>").attr('href','#').attr('id','dyn-grid-view').text('Grid View').click(function ()
		{
			$('#animal-list_wrapper').hide();
			$('#dyn-list-view').removeClass('active');
			$('#dyn-grid-view').attr('class', 'active');
			$('#animal-grid').show();
			return false;
		}));
		
		//var aBottomListView = $("<a>").attr('href','#').attr('id','dyn-list-view').text('List View').click(showListView);
		//var aBottomGridView = $("<a>").attr('href','#').attr('id','dyn-grid-view').text('Grid View').click(showGridView);
		
		//$(divViewOptionsTop).append(aTopListView);
		//$(divViewOptionsTop).append(aTopGridView);
		
		//$(divViewOptionsBottom).append(aBottomListView);
		//$(divViewOptionsBottom).append(aBottomGridView);
		
		$('#animals').prepend(divViewOptionsTop);
		//$('#body').append(divViewOptionsBottom);
		
		$('#animal-list').dataTable();
	}
});