$(document).ready(function() {
	SwapImage.rollover.init();
	//initSIFR();
	verticallyAlignImages();

	$("#changeCategory").change(function() {
		document.location.href = this.value;
	});
	
	if($('.weeksMessage').length > 0) {
	    function moveIt(which) {
	        current = $('#weeksNav li').children('ul:visible').attr('order');
	        if(which == "plus") {
	            current = parseFloat(current)+1;
	        } else {
	            current = parseFloat(current)-1;
	        }
	        filter = "[order = "+current+"]"
            $('#weeksNav li').children('ul').hide();
            $('#weeksNav li').children('ul'+filter).show();
	    }
	    
	    current = "0";
	    $('#weeksNav li').children('ul').each(function(i) {
	      $(this).attr('order', i);  
	      last = i+"";
	    }).not(':first').hide();
	    
	    $('#weeksLeft').click(function() {
	        if(current != "0") {
                moveIt('minus');
                return false;
                
	        }
	    });
	    
	    $('#weeksRight').click(function() {
	        if(current != last) {
	            moveIt('plus');
	            return false;
                
	        }
	    });
	}
    
});

initSIFR();

/***** ImageRollovers ****************************************************************************************/

SwapImage = {};

SwapImage.rollover =
{
	init: function() {
		this.preload();

		$("img.ro,input.ro").hover(
         function() { $(this).attr('src', SwapImage.rollover.newimage($(this))); },
         function() { $(this).attr('src', SwapImage.rollover.oldimage($(this))); }
      );
		$("a.ro").hover(
	     function() { $(this).children('img').attr('src', SwapImage.rollover.newimage($(this).children('img'))); },
	     function() { $(this).children('img').attr('src', SwapImage.rollover.oldimage($(this).children('img'))); }
	  );

	},

	preload: function() {
		$(window).bind('load', function() {
			$('img.ro,input.ro').each(function(key, elm) { $('<img>').attr('src', SwapImage.rollover.newimage($(this))); });
			$('a.ro').each(function(key, elm) { $('<img>').attr('src', SwapImage.rollover.newimage($(this).children('img'))); });
		});
	},

	newimage: function(img) {
		return img.attr('data-srcRollover') || img.attr('src').replace(/\.(\w{3})/g, "_over.$1");
	},
	oldimage: function(img) {
		return img.attr('data-srcOriginal') || img.attr('src').replace(/_over\.(\w{3})/g, ".$1");
	}
};

/***** SIFR ****************************************************************************************/

function _initSIFR()
{
	$('.sifr').sifr({
		//font: "http://jquery.thewikies.com/sifr/themes/cleap/fonts/Cochin.swf",
		font: "/assets/swf/arial_black.swf",
		version: 3,
		build: '436',
		over: 1.5,
		resizable: true
	});
}
	
function initSIFR()
{
	var arialBlack = { src: '/assets/swf/arialBlack.swf' };

	sIFR.activate(arialBlack);
	
	var settings = {
		selector: '#birdWrap h3, .sifr',
		ratios: [10, 1.6, 16, 1.53, 17, 1.47, 19, 1.48, 21, 1.47, 23, 1.48, 31, 1.46, 34, 1.45, 51, 1.44, 77, 1.43, 78, 1.42, 81, 1.43, 87, 1.42, 88, 1.43, 1.42],
		css: {
			'.sIFR-root': {
				'letter-spacing': '-2',
				'leading': '-15'
			}
		},
		offsetTop: -10,
		tuneHeight: -16,
		wmode: 'transparent'
	}
	
	settings.css['.about'] = { 'color': '#3ab54b' };
	settings.css['.basket'] = { 'color': '#5574b8', 'text-align': 'center' };
	settings.css['.shop'] = { 'color': '#9e005d', 'text-align': 'center' };
	settings.css['.tradeShop'] = { 'color': '#9e005d', 'text-align': 'left' };
	settings.css['.contact'] = { 'color': '#545554' };
	settings.css['.notAllBirds'] = { 'color': '#ec008b' };
	settings.css['.mailingList'] = { 'color': '#005826', 'text-align': 'right' };
	settings.css['.order'] = { 'color': '#f4989d', 'text-align': 'center' };
	settings.css['.orderSuccess'] = { 'color': '#2e3091', 'text-align': 'center' };
	settings.css['.weeksMessage'] = { 'color': '#ec1d24' };
	settings.css['.other'] = { 'color': '#0095da', 'text-align': 'right' };
	settings.css['.trade'] = { 'color': '#f26522' };
	settings.css['a'] = { 'color': '#f26522' };
	settings.css['.contactThanks'] = { 'color': '#8c6239', 'margin-left': '8', 'leading': '-4' };
	settings.css['.mailingListThanks'] = { 'color': '#00a651', 'text-align': 'center', 'leading': '-4' };
	settings.css['.legal'] = { 'color': '#7d707e', 'text-align': 'center' };
	
	sIFR.replace(arialBlack, settings);
	sIFR.replace(arialBlack, {
		selector: '#birdWrap li',
		ratios: [10, 1.6, 16, 1.53, 17, 1.47, 19, 1.48, 21, 1.47, 23, 1.48, 31, 1.46, 34, 1.45, 51, 1.44, 77, 1.43, 78, 1.42, 81, 1.43, 87, 1.42, 88, 1.43, 1.42],
		css: {
			'.sIFR-root': {
				'letter-spacing': '-2',
				'leading': '-15',
				'color': '#a5dbde',
				'text-align': 'right'
			},
			'a': {
				'color': '#a5dbde',
				'text-decoration': 'none'
			},
			'a:hover': {
				'color': '#00746a'
			},
			'.current': {
				'color': '#00746a'
			}
		},
		offsetTop: -6,
		tuneHeight: -16,
		wmode: 'transparent'
	});
	
}

/***** Vetically Align Images ****************************************************************************************/

function verticallyAlignImages()
{
	$('#cardSelect table.subCatagory tr.images img').load(function()
	{
		var mt = ($(this).parent().height() - $(this).outerHeight())/2;
		$(this).css('margin-top', mt);
	});
	
	$('#basketWrap .row .left img').load(function()
	{
		var mt = (92 - $(this).outerHeight())/2;
		if (mt > 0) {
			$(this).css('margin-top', mt);
		}
	})
}