var frutiger = {
	src: webroot + 'swf/frutiger-cnbold.swf',
	wmode: 'transparent',
	fitExactly: true,
	css: [
		'.sIFR-root { color: #00653a; text-transform: uppercase}',
		'a { color: #ef000e; text-decoration: none; }',
		'a:hover { color: #00653a }'
	]
}

var odile = {
	src: webroot + 'swf/odile.swf',
	wmode: 'transparent',
	css: [
		'.sIFR-root { color: #00653a;}',
		'a { color: #ef000e; text-decoration: none; }',
		'a:hover { color: #00653a }'
	]
}

sIFR.activate(frutiger, odile);

sIFR.replace(odile, {
	selector: 'h1'
});

sIFR.replace(frutiger, {
	selector: '#nl h3, #Events #otherevents h3',
	css: [
	'.sIFR-root { color: #ffffff; text-transform: uppercase}',
	'a { color: #ef000e; text-decoration: none; }',
	'a:hover { color: #00653a }'
	],
	ratios: [6,1.3,7,1.26,8,1.22,9,1.21,10,1.19,11,1.18,12,1.2,13,1.19,14,1.18,15,1.16,16,1.16,17,1.15,18,1.16,19,1.15,20,1.14,21,1.14,22,1.13,23,1.13,24,1.14,25,1.14,26,1.13,27,1.13,28,1.13,29,1.12,30,1.13,31,1.12,32,1.12,33,1.12,34,1.12,35,1.11,36,1.12,37,1.12,38,1.12,39,1.11,40,1.11,41,1.11,42,1.11,43,1.11,44,1.11,45,1.11,46,1.11,47,1.11,48,1.11,49,1.11,50,1.11,51,1.11,52,1.11,53,1.11,54,1.11,55,1.11,56,1.1,57,1.1,58,1.1,59,1.1,60,1.11,61,1.11,62,1.1,63,1.1,64,1.1,65,1.1,66,1.1,67,1.1,68,1.1,69,1.1,70,1.1,71,1.1,72,1.1,73,1.1,74,1.1,75,1.1,76,1.1,77,1.1,78,1.1,79,1.1,80,1.1,81,1.1,82,1.1,83,1.1,84,1.1,85,1.1,86,1.1,88,1.1,89,1.1,90,1.1,91,1.1,92,1.1,93,1.1,94,1.1,95,1.09,96,1.1,97,1.1,98,1.1,99,1.1,100,1.1,101,1.1,102,1.1,103,1.1,104,1.09,105,1.09,106,1.09,107,1.09,108,1.1,109,1.1,110,1.1,111,1.09,112,1.09,113,1.09,114,1.09,115,1.09,116,1.09,117,1.09,118,1.09,119,1.09,120,1.1,121,1.09,122,1.09,123,1.09,124,1.09,1.09]
});
sIFR.replace(frutiger, {
	selector: 'h3',
	ratios: [6,1.3,7,1.26,8,1.22,9,1.21,10,1.19,11,1.18,12,1.2,13,1.19,14,1.18,15,1.16,16,1.16,17,1.15,18,1.16,19,1.15,20,1.14,21,1.14,22,1.13,23,1.13,24,1.14,25,1.14,26,1.13,27,1.13,28,1.13,29,1.12,30,1.13,31,1.12,32,1.12,33,1.12,34,1.12,35,1.11,36,1.12,37,1.12,38,1.12,39,1.11,40,1.11,41,1.11,42,1.11,43,1.11,44,1.11,45,1.11,46,1.11,47,1.11,48,1.11,49,1.11,50,1.11,51,1.11,52,1.11,53,1.11,54,1.11,55,1.11,56,1.1,57,1.1,58,1.1,59,1.1,60,1.11,61,1.11,62,1.1,63,1.1,64,1.1,65,1.1,66,1.1,67,1.1,68,1.1,69,1.1,70,1.1,71,1.1,72,1.1,73,1.1,74,1.1,75,1.1,76,1.1,77,1.1,78,1.1,79,1.1,80,1.1,81,1.1,82,1.1,83,1.1,84,1.1,85,1.1,86,1.1,88,1.1,89,1.1,90,1.1,91,1.1,92,1.1,93,1.1,94,1.1,95,1.09,96,1.1,97,1.1,98,1.1,99,1.1,100,1.1,101,1.1,102,1.1,103,1.1,104,1.09,105,1.09,106,1.09,107,1.09,108,1.1,109,1.1,110,1.1,111,1.09,112,1.09,113,1.09,114,1.09,115,1.09,116,1.09,117,1.09,118,1.09,119,1.09,120,1.1,121,1.09,122,1.09,123,1.09,124,1.09,1.09]
});


// End sIFR



rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd()
{
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};

function rand(number)
{
return Math.ceil(rnd()*number);
};

$(function(){
	
	$(document).pngFix();
	
	$('a').click(function(){this.blur()});
	
	if ($('body').attr('id') == 'Index') {
		$('.topgrid').each(function(){
			$(this).cycle({
				timeout: 4000 + 300 * rand(10),
				delay: rand(5) * 1000 - 4000,
				speed: 1500
			});
		});
	}
	
	$(".mp3player").media( { width: 300, height: 20 } );
	// $(".mp3player").jPlayer(
	// 		{
	// 			ready: function(){ $(this).setFile($(this).attr('src')); },
	// 			swfPath: "http://www.readingterminalmarket.org/app/webroot/mp3/"
	// 		});

});

jQuery.Randomizer = {
	build: function(images, imgdir) {
		$(this).attr('src',imgdir + images[Math.ceil(Math.random()*images.length)-1]);
	}
};

jQuery.fn.Randomize = jQuery.Randomizer.build;

jQuery.fn.minHeight = function()
{
	this.each(function(){		
		var mh = $(this).css('min-height');
	    var mhsize = mh.replace(/px/,'');
	    var h = $(this).height();
		
	    if (h < mhsize) $(this).css('height',mh);
	});
    
};

jQuery.merchantMap = {
	clearTip: function()
	{	
		if ( $('#instructions') && !$(this).attr('href') )
			$('#instructions').remove();

		if ($('#nameTip')) $('#nameTip').remove();
	},
	highlight: function( mid ) {
		
		var areas = $('area[@merchant_id="'+mid+'"]');
		
		areas.each(function(){
			var coords = $(this).attr('coords').split(',');
			var imgx = $('#imgmap')[0].offsetLeft;
			var imgy = $('#imgmap')[0].offsetTop;
			
			var x = parseInt(coords[0].trim());
			var y = parseInt(coords[1].trim());
			
			jQuery.merchantMap.clearTip();
			$('#imgmap').after('<div id="nameTip" style="display: none;"><div class="merchantsTip">' + $(this).attr('title') + '</div></div>');
			
			$('#nameTip').css({position: 'absolute',left: (x + imgx + 1) +'px', top: (y + imgy - 25) +'px', zIndex: 5000, display: 'block' });
			
		})
	}
};

livesearch = {
  t: 0,
  qCache: '',
  search: function() {
	var q = $('#msearch').val();
	if (this.qCache == q) return false;
    if(q != '')
    {
		this.qCache = q;
        $('#spinner').show();
        $('#results').load( webroot + 'merchants/search/' + q, function(){
          $('#spinner').hide();
        });
    }
    else
    {
        $('#results').empty();
    }
  }
};

String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};