/** Navigation **/
$(document).ready(function(){


	$('#navigation img').mouseover(function(){
		this.src = this.src.replace(/([^\.]+)\.png/, '$1-hover.png');
	}).mouseout(function(){
		this.src = this.src.replace(/-hover/, '');
	});
	$('#navigation>li').mouseover(function(){
		$(this).find('ul').show();
	}).mouseout(function(){
		$(this).find('ul').hide();
	});
	
});


/** Commercials **/
$(document).ready(function(){
	if(typeof(spots) != "undefined"){ 
		$('#copy').after('<div id="video"></div>').next()
			.append('<div id="player_pad"><div id="player"></div></div>')
			.append('<div id="spots"></div>').find('#spots')
				.append('<ul id="thumbs"></ul>');
		for(i=0; i<spots.length; i++){
			$('#thumbs').append('<li></li>').find('li:last')
				.append('<a rel="'+spots[i].file+'">'+spots[i].title+'</a>')
				.find('a').prepend('<img src="'+HTPATH+'/commercials/tn/'+spots[i].file+'.jpg"/>')
				.click(function(){
					vid = HTPATH + '/commercials/'+$(this).attr('rel')+'.flv';
					swfobject.embedSWF(
						HTPATH+'/style/swf/video_player.swf?video='+vid,
						'player', '286', '223', '9.0.0', false, false, {menu: 'false'}
					);
				});
		}
		$('#thumbs a:first').click();
		if($('#thumbs li').length == 1)
			$('#thumbs').remove();
	}
});

/** WGN Audio **/
$(document).ready(function(){
	if(typeof(aspots) != "undefined"){ 
	
		$('#copy').after('<div id="audio"></div>').next()
			.append('<div id="player_pad"><div id="player"></div></div>')
			.append('<div id="spots"></div>').find('#spots')
				.append('<ul></ul>');	
		for(i=0; i<aspots.length; i++){
			$('#spots ul').append('<li></li>').find('li:last')
				.append('<a rel="'+aspots[i].file+'">'+aspots[i].title+'</a>').find('a')
				.click(function(){
					file = HTPATH+'/commercials/wgn/'+$(this).attr('rel')+'.mp3';
					swfobject.embedSWF(
						HTPATH+'/style/swf/audio_player.swf?mp3='+file, 
						"player", "356", "94", "9.0.0", false, false, {menu: "false"});
					
				});
		}	
	}
});

/** Art SWFs **/
$(document).ready(function(){
	if(typeof(artSWF) != "undefined"){
		$('#copy').after('<div id="art"></div>');
		swfobject.embedSWF(HTPATH+"/style/swf/"+artSWF, "art", "280", "260", "7.0.0", false, false, {menu: "false"});
	}
});


/** Directions **/
$(document).ready(function(){
	if($('body.directions').length == 0) return;
	if($('body.courtesy-shuttle-service').length != 0) return;
	var GoodsMap = {
		store: '220 Main Street North, Kewanee, IL 61443',
		infoHTML: '<address id="info">200 Main Street North<br/>Kewanee, IL 61433<br/>309.852.5656</address>',
		fromDefault: 'City, State or Zip',
		makeMap: (function(){	
			var map = new GMap2(document.getElementById("map_canvas"));
			from = document.getElementById('start').value;
			if(from == '' || from == this.fromDefault){
				var geocoder = new GClientGeocoder();
				info = this.infoHTML;
				geocoder.getLatLng(
					this.store,
					function(point) {
						map.setCenter(point, 7);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						marker.openInfoWindowHtml(info);
					}
				);
			} else {
				directionsPanel = document.getElementById("route");
				directions = new GDirections(map, directionsPanel);
				directions.load("from: "+from+" to: 200 North Main Street, Kewanee, IL");
			}
		})
	};
	$('#copy').after('<div id="map"></div>').next()
		.append('<div id="map_canvas"></div><input id="start" type="text" value="City, State or Zip"/><button>Show Route</button>');
		
	$('#map button').mouseup(function(){
		GoodsMap.makeMap();
	});	
	GoodsMap.makeMap();
});