jQuery.noConflict();
jQuery(document).ready(function($){
	
	var frontend = 
	{
		init:function()
		{
			this.external();
			this.imageFormAction();
			this.regionTunes();
		},
		
		external:function()
		{
			$("a").each(function()
			{
    			if ($(this).attr("rel") == "external") 
				{
      				$(this).attr("target", "_blank");
    			}
  			});
		},
		
		imageFormAction:function()
		{
			if($('input.rollover').length > 0)
			{
				var oldsrc;
				$('input.rollover').hover(function(){
					oldsrc = $(this).attr('src');
		            var img = oldsrc.split('.');
		            var newsrc = img[0] + "_over." + img[1];
		            $(this).attr('src', newsrc);
		        }, function(){
		            $(this).attr('src', oldsrc);
				});
			}
		},
		
		regionTunes:function()
		{
			if($('#OutletRegion').length > 0)
			{
				$rs = $('#Form_VoteForm_OutletRegion');
				$tunes = $('#Form_VoteForm_ChipTuneID');
				$tunesOptions = $tunes.children();
				$empty = $tunes.children().eq(0);
				
				$rs.change(function()
				{
					$tunes.children().remove();
					$tunes.append($tunesOptions);
					var t = $rs.children(":selected").text();
					$tunes.children().remove(':not(:contains('+t+'))');
					$tunes.prepend($empty).children().eq(0).attr("selected", "selected");			
				});
			}
		}
	}
	
	frontend.init();  
});
