var after_next = 0;
var ply_top_right;
var ply_current_song;
var ply_next_song_img;
var ply_next_song_txt;
var ply_next_song;
var button_last_song;
var location_select;
var gen_select;
var ply_last_song_img;
var ply_last_song_txt;
var video_player_holder;
var ply_band_store_image;
var audio_player_holder;
var player_current_band_image;
var ply_other_band_info;
var fa_w_image_holder_img;
var cookie_gen;
var cookie_loc;
var schedule_dialog;
var popup_connected;
var doInterval;
jQuery('document').ready(
     function(){
	  button_last_song = jQuery('#ply_last_song');
	  ply_top_right = jQuery('#ply_top_right');
	  ply_current_song = jQuery('#ply_current_song');
	  ply_next_song_img = jQuery('#ply_next_song_img');
	  ply_next_song_txt = jQuery('#ply_next_song_txt');
	  location_select =jQuery('#location_select');
	  ply_next_song = jQuery('#ply_next_song');
	  gen_select = jQuery('#gen_select');
	  ply_last_song_img = jQuery('#ply_last_song_img');
	  ply_last_song_txt = jQuery('#ply_last_song_txt');
	  video_player_holder = jQuery('#video_player_holder');
	  ply_band_store_image = jQuery('#ply_band_store_image');
	  audio_player_holder = jQuery('#audio_player_holder');
	  player_current_band_image = jQuery('#player_current_band_image');
	  ply_other_band_info = jQuery('#ply_other_band_info');
	  fa_w_image_holder_img = jQuery('.fa_w_image_holder img');
	  handle_cookies_for_dropdowns();
	  load_google_analytics();
	  load_ads();
	  load_feature_bands();
	  load_player_ad();
	  player_overlay();
	  load_location(0);
	  load_gen(0);
	  location_change_handler();
	  change_station_button_handler();
	  //var 	  pop_up_player_win = window.open(null,"IMRadio_Player");
	  //pop_up_player_win.refresh_clipinfo();
	  jQuery('#player_control_bar').append('<a class="pause" onclick=" click_play_button_on_player();">play</a>');
	  //doInterval = setInterval(scroll_feature_artists,1000);
     }
);
function click_play_button_on_player(){
    open_the_player();
     pop_up_player_win.click_play_button_on_player();
}
function reconnect_window(){
    // lee_debug('reconnect window');
    open_the_player();

     
     //pop_up_player_win = window.open(null,"IMRadio_Player");
}
function playbutton_handler(state){
     lee_debug('function: playbutton_handler state:'+state);
     if(state=='pause'){
	 jQuery('.pause').removeClass().addClass('play');

     }
     if(state=='play'){
	  //alert('play');
	  jQuery('.play').removeClass().addClass('pause');
	 
     }
}
function lee_debug(msg){
     try{
	  console.info(msg);
     }
     catch(err){
	  
     }
}
function handle_cookies_for_dropdowns(){
     //lee_debug('function:  handle_cookies_for_dropdowns ');
     cookie_loc = jQuery.cookie("user_selected_loc");
     cookie_gen = jQuery.cookie("user_choosen_gen");
     if(cookie_loc==null){
	  cookie_loc = '0';
	  //lee_debug('cookie_loc is null?');
     }
     if(cookie_gen==null){
	  cookie_gen = '0';
     }
}
function load_google_analytics(){
     //lee_debug('function:  load_google_analytics ');
     var _gaq = _gaq || [];
	  _gaq.push(['_setAccount', 'UA-5675808-2']);
	  _gaq.push(['_trackPageview']);

	  (function() {
	       var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	       ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	       var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	  })();
}

function load_ads(){
	  //lee_debug('function:  load_ads');
	  jQuery('#banner_ad').append("<iframe id='ac388be1' name='ac388be1' src='http://d1.openx.org/afr.php?zoneid=171652&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE' frameborder='0' scrolling='no' width='728' height='90' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=af8329d1&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171652&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=af8329d1' border='0' alt='' /></a></iframe>");
	  jQuery('#left_ad1').append("<iframe id='a6705a97' name='a6705a97' src='http://d1.openx.org/afr.php?zoneid=171655&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE' frameborder='0' scrolling='no' width='125' height='125' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=aac0de35&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171655&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=aac0de35' border='0' alt='' /></a></iframe>");
	  jQuery('#left_ad2').append("<iframe id='a4ff597f' name='a4ff597f' src='http://d1.openx.org/afr.php?zoneid=171654&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE' frameborder='0' scrolling='no' width='120' height='600' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=aaf47f9a&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171654&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=aaf47f9a' border='0' alt='' /></a></iframe>");
	  jQuery('#right_ad1').append("<iframe id='a8852cff' name='a8852cff' src='http://d1.openx.org/afr.php?zoneid=171653&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE' frameborder='0' scrolling='no' width='300' height='250' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=a527cfc8&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171653&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a527cfc8' border='0' alt='' /></a></iframe>");
	  jQuery('#right_ad2').append("<iframe id='aa6f560e' name='aa6f560e' src='http://d1.openx.org/afr.php?zoneid=171952&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE' frameborder='0' scrolling='no' width='300' height='250' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=a4396337&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171952&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=a4396337' border='0' alt='' /></a></iframe>");
}

function load_feature_bands(){
	  //lee_debug('function:  load_feature_bands');
//	  jQuery("#featured_artists_scroller").append('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'+
//	       'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"'+
//	       'width="470"'+
//	       'height="250"'+
//	       'id="flashmo_098_3d_curve_wall"'+
//	       'align="middle">'+
//	       '<param name="allowScriptAccess" value="sameDomain" />'+
//	       '<param name="allowFullScreen" value="false" />'+
//	       '<param name="movie" value="flashmo_098_3d_curve_wall.swf" />'+
//	       '<param name="quality" value="high" />'+
//	       '<param name="scale" value="exactfit" />'+
//	       '<param name="bgcolor" value="#000000" />'+
//	       '<embed src="flashmo_098_3d_curve_wall.swf" quality="high"'+
//	       'scale="exactfit" bgcolor="#000000" width="470" height="250"'+
//	       'name="flashmo_098_3d_curve_wall" align="middle"'+
//	       'allowScriptAccess="sameDomain" allowFullScreen="false"'+
//	       'type="application/x-shockwave-flash"'+
//	       'pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
//	       '</object>');
}

function load_player_ad(){
     //lee_debug('function:  load_player_ad');
     ply_band_store_image.empty();
     ply_band_store_image.append("<iframe id='a7077199' name='a7077199' src='http://d1.openx.org/afr.php?zoneid=171973&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;ct0=INSERT_CLICKURL_HERE' frameborder='0' scrolling='no' width='468' height='60' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=aebbf3aa&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=171973&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=aebbf3aa&amp;ct0=INSERT_CLICKURL_HERE' border='0' alt='' /></a></iframe>");
}
function load_store_ad(band_ad,band_store){
     if(band_ad==1){
	  ply_band_store_image.empty();
	  ply_band_store_image.append("<iframe id='a37640d4' name='a37640d4' src='http://d1.openx.org/afr.php?zoneid=179574&link_url="+band_store+"&amp;target=_blank&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;ct0="+band_store+"' frameborder='0' scrolling='no' width='468' height='60' allowtransparency='true'><a href='http://d1.openx.org/ck.php?n=ad0a3e2e&amp;cb=INSERT_RANDOM_NUMBER_HERE' target='_blank'><img src='http://d1.openx.org/avw.php?zoneid=179574&amp;cb=INSERT_RANDOM_NUMBER_HERE&amp;n=ad0a3e2e&amp;ct0=INSERT_CLICKURL_HERE' border='0' alt='' /></a></iframe>");

     }
     else{
	  if(band_ad == 0){
	       load_player_ad();
	  }
     }
}
function load_location(genera){
     //lee_debug('function:  load_location('+genera+')');
     jQuery.get('http://www.imradio.com/views/mainparts/get_location_ajax.php',{
	  gen:genera
     },function(data){
	  location_select.empty();
	  location_select.append('<option value="0">All Locations</option>');
	  location_select.append(data);
     });
}
function location_change_handler(){
     //lee_debug('function:  location_change_handler');
     location_select.change(function(){
	  selected_gen=gen_select.val();
	  selected_loc=location_select.val();
	  load_gen(selected_loc);
     });
}
function load_gen(location){
     //lee_debug('function:  load_gen('+location+')');
     //pop_up_player_win.load_gen(location)
     jQuery.get('http://www.imradio.com/views/mainparts/get_genre_ajax.php',{
	  loc:location
     },function(data){
	  gen_select.empty();
	  gen_select.append('<option value="0">All Genre</option>');
	  gen_select.append(data);
	  gen_select.val(cookie_gen);
     });
}
function schedule_button(){
	  //lee_debug('function:  schedule_button');
	if(schedule_dialog==1){
		 jQuery('#schedule_holder').dialog('open');
		 jQuery('#sch_chan_button').click();
	 }
	 else{
		 create_schedule_grid();
	 }

}
function gettimeoffset(){
     //lee_debug('function:  gettimeoffset');
     var ourDate = new Date();
     return ourDate.getTimezoneOffset();
}

var search_dialog;
function create_search_dialog(){
	jQuery('#search_dialog').remove();
	jQuery('body').append('<div id="search_dialog" class="search_dialog" style="overflow-y: auto;height: 300px;"></div>');
	var searchfor = jQuery('#search_name').val();
	jQuery.get('/views/mainparts/search_results.php?f=search&sitesearch=Site+Search',{search_name:searchfor}, function(data){jQuery('#search_dialog').append(data).dialog({height:350,width:350,title:'IMRadio Search For ',dragStop:function(){ $(document).unbind('mousemove');}	});});

}
function change_station_button_handler(){
     jQuery('#chan_button').click(function(){
	  open_the_player();

	  selected_gen=gen_select.val();
	  selected_loc=location_select.val();
	  lee_debug('location:'+selected_loc+' gen:'+selected_gen);
	  pop_up_player_win.jQuery('#location_select').val(selected_loc);
	  pop_up_player_win.jQuery('#gen_select').val(selected_gen);
	  
	  pop_up_player_win.jQuery('#chan_button').click();
     });
}
function player_overlay(){
     var mpos = jQuery('#audio_player').position();
     jQuery('body').append('<div id="player_overlay" onclick="open_the_player();" ><img src="http://www.imradio.com/views/images/click_to_play.gif" style="display: block;margin-left: auto;margin-right: auto" ></img></div>');
     jQuery('#player_overlay').width(jQuery('#audio_player').width()).height(jQuery('#audio_player').height()).css('background-color','black').css('position','absolute').css('left',mpos.left).css('top',mpos.top);
}
   var pop_up_player_win=false;
function open_the_player(popme,from_recent_song){
//     if (opener && !opener.closed){
	 // pop_up_player_win.focus();
//     }
//     else {
//	  var l = '0';
//	  var g ='0' ;
//	  pop_up_player_win = window.open('http://www.imradio.com/views/mainparts/standalone_player.php?loc='+l+'&gen='+g,"IMRadio_Player",'height=500,width=720,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
//	  opener = pop_up_player_win;
	  //pop_up_player_win.focus();
//     }
     if(!popme){
	  popme= false;
     }
	  pop_up_player_win = window.open('',"IMRadio_Player",'height=500,width=720,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
	  if(!pop_up_player_win||pop_up_player_win.closed||!pop_up_player_win.playerMouseOver){
	       var l = '0';
	       var g ='0' ;
	       if(from_recent_song == 1){
		    pop_up_player_win = window.open('http://www.imradio.com/views/mainparts/standalone_player.php?loc='+l+'&gen='+g+'&getsong=1',"IMRadio_Player",'height=500,width=720,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
	       }else{
		    pop_up_player_win = window.open('http://www.imradio.com/views/mainparts/standalone_player.php?loc='+l+'&gen='+g,"IMRadio_Player",'height=500,width=720,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');
	       }
	  }
	  else{
	       if(popme){
		    pop_up_player_win.focus();
	       }
	  }

}
function load_song_info(song_image,artist_link,song_Description,genre,song_title,artist,bandlocation,starrate_base,band_id,song_id){
          jQuery(document).ready(function(){
	       if(popup_connected==song_title){

	       }else{
		  //popup_connected=song_title;
		  jQuery('#player_overlay').remove();
		  player_current_band_image.empty();
        	  player_current_band_image.append('<image width="150px" src='+song_image+' onclick="pop_out_player_link(0,0,\''+artist_link+'\');" ></image>');
        	  ply_other_band_info.empty();
        	  ply_other_band_info.append('Description: '+song_Description+'<hr>Genre: '+genre+'<br>Location:'+bandlocation);
        	  var starrate_base_img_string = "";
        	  var star_base_count = 5;
        	  //lee_debug(star_base_count);
        	  star_baser = parseInt(starrate_base);
        	  while(star_base_count>0){
        		  if(star_baser>0){
        			  starrate_base_img_string = starrate_base_img_string+"<image width='20px' height='20px' src='http://www.imradio.com/views/images/gicon.png' />";
        		  }
        		  else{
        			  starrate_base_img_string = starrate_base_img_string+"<image width='20px' height='20px'  src='http://www.imradio.com/views/images/gicon_dark.png' />";
        		  }
        		  star_base_count = star_base_count-1;
        		  star_baser = star_baser-1;
        	  }
        	 try{
			 // dropped till tested Lee
        		band_info_holder.append('<hr> <div id="Rating" onclick="review_band('+band_id+','+starrate_base+','+song_id+',\''+song_title+'\');">Rate & Review This Song:<br>'+starrate_base_img_string+'</div>');
        		// band_info_holder.append('<hr> <div id="Rating" onclick="">'+starrate_base_img_string+'</div>');
        	 }catch(err){
        		 //lee_debug('the error is...'.err);
        	 }
        	  ply_top_right.empty();
        	  ply_top_right.append(song_title+' by '+artist+'');

	       ply_current_song.empty();
	       ply_current_song.append('<span class="span-3 current_song" id="current_song">Now Playing</span><image width="50px" src='+song_image+'></image><br><span class="curplaysongtitle">'+song_title+'</span>');
	       fa_w_image_holder_img.css('visibility','visible');
	       }
     });
}
function load_next_button(next_song_image,next_song_title,next_song_index,number_of_clips,song_title){
     jQuery(document).ready(function(){
	  if(popup_connected==song_title){

	  }else{
	       
	       ply_next_song_img.empty();
	       ply_next_song_img.append('<image width="75px" src='+next_song_image+'></image>');
	       ply_next_song_txt.empty();
	       ply_next_song_txt.append(next_song_title);
	       ply_next_song.unbind('click');
	       ply_next_song.click(function(){
	       open_the_player();
	       pop_up_player_win.play_next_clip(next_song_index,number_of_clips);

	       });
	  }
     });
}
var mysong_array;
function play_song(song_array,from_recent_song){
     if(from_recent_song==undefined){
	  from_recent_song = 0;
     }
     mysong_array = song_array
     open_the_player(false,from_recent_song);
     pop_up_player_win.play_song(song_array);
}
function show_artist(a_id){
     window.location = 'http://www.imradio.com/index_main.php?f=artists_view&hide_player=true&id='+a_id;
}
function load_previous_button(previous_song_index,previous_song_title,previous_song_image,song_title){
     jQuery(document).ready(function(){
	  if(popup_connected==song_title){
	       lee_debug('title_issue');
	  }else{
	       popup_connected=song_title;
	       lee_debug('title fine');
	       ply_last_song_img.empty();
	       ply_last_song_img.append('<image width="75px" src='+previous_song_image+'></image>');
	       ply_last_song_txt.empty();
	       ply_last_song_txt.append(previous_song_title);
	       button_last_song.unbind('click');
	       button_last_song.click(function(){
		    open_the_player();
		    pop_up_player_win.play_previous_song(previous_song_index);
	       });
	  }
     });
}
function pop_out_player_link(a,b,artist_link){
     window.location=artist_link;
}
function create_schedule_grid(){
    jQuery("#list1").jqGrid(
      {
	    url:'http://www.imradio.com/views/mainparts/schedule_xml.php?l=0&g=0&first=0&localtime='+gettimeoffset()+'&page_num=2',
	    datatype: "xml",
	    colNames:[
		 'Thumbnail',
		 'Song',
		 'Link',
		 'Artist',
		 'Description',
		 'Rating',
		 'Genre',
		 'Play',
		 'SongDuration',
		 'StarRating',
		 'location',
		 'storeURL',
		 'userID',
		 'scheduled'
	    ],
	    colModel:[
        {
    		name:'Thumbnail',
    		index:'Thumbnail',
    		width:20,
    		sortable:false,
    		xmlmap:"mediathumbnail"
		} ,
		 {
		      name:'Song',
		      index:'Song',
		      width:50,
		      xmlmap:"title"
		 },
		 {
		      name:'Link',
		      index:'Link',
		      width:0,
		      xmlmap:"link"
		 },
		 {
		      name:'Artist',
		      index:'Artist',
		      width:50,
		      xmlmap:"mediaartist"
		 },
		 {
		      name:'Description',
		      index:'Description',
		      width:0,
		      align:"right",
		      xmlmap:"mediadescription",
		      classes:'wrap'
		 },
		 {
		      name:'Rating',
		      index:'Rating',
		      width:0,
		      align:"right",
		      xmlmap:"mediarating"
		 },
		 {
		      name:'Genre',
		      index:'Genre',
		      width:0,
		      align:"right",
		      xmlmap:"mediakeywords"
		 },
		 {
		      name:'Songurl',
		      index:'Songurl',
		      width:0,
		      sortable:false,
		      xmlmap:"mediacontent"
		 } ,
		 {
		      name:'SongDuration',
		      index:'SongDuration',
		      width:0,
		      sortable:false,
		      xmlmap:"mediaduration"
		 } ,
		 {
		      name:'StarRating',
		      index:'StarRating',
		      width:0,
		      sortable:false,
		      xmlmap:"mediastarRating"
		 } ,
		 {
		      name:'location',
		      index:'location',
		      width:0,
		      sortable:false,
		      xmlmap:"bandlocation"
		 } ,
		 {
		      name:'storeURL',
		      index:'storeURL',
		      width:15,
		      sortable:false,
		      xmlmap:"storeURL"
		 } ,
		 {
		      name:'userID',
		      index:'userID',
		      width:0,
		      sortable:false,
		      xmlmap:"fkuserid"
		 } ,
		 {
		      name:'sched',
		      index:'sched',
		      width:30,
		      sortable:false,
		      xmlmap:"schedule"
		 }
	    ],
	    height:'auto',
	    viewrecords: true,
	    width:415,
	    pager: jQuery('#pager1'),
	    rowNum:10,
	    rowList:[10,20,30],
	    xmlReader:
		    {
		    	root : "items",
		    	row: "item",
		    	repeatitems: false,
		    	id:'schedid',
		    	page:'currentpage',
		    	total:'totalpages',
		    	records:'records'

			 },
	    caption:"Schedule" ,
	    loadComplete:function(){

				    jQuery('#schedule_holder').dialog({resizable:false,title:'Schedule',minHeight:300,minWidth:600,dragStop:function(){ $(document).unbind('mousemove');},open:function(){schedule_dialog = 1;}});
				    change_station_button_handler_schedule();

			 },
		onSelectRow:function(rowid,status){
				 var schedgrid = jQuery('#list1');
				 var userID = chedgrid.getCell(rowid,'userID');
				 var artistdata = get_min_profile(userID);
			 },
	    afterInsertRow: function(rowid,rowdata,rowelem ){
				 		var imagefield;
				 		var band_link;
				 		var songlink;
				 		var storeurl;
				 		var band_name;
				    	var schedgrid = jQuery('#list1');
						imagefield = schedgrid.getCell(rowid,'Thumbnail');
						band_link = schedgrid.getCell(rowid,'Link');
						schedgrid.setCell(rowid,'Thumbnail','<a href="'+band_link+'"><image src="'+imagefield+'" width="50px" /></a>');
						schedgrid.hideCol('Link');
						schedgrid.hideCol('userID');
						schedgrid.hideCol('SongDuration');
						schedgrid.hideCol('Rating');
						schedgrid.hideCol('StarRating');
						schedgrid.hideCol('Description');
						schedgrid.hideCol('Genre');
						schedgrid.hideCol('location');
						var playbutton = "http://www.imradio.com/views/images/playbutton.png";
						songlink = schedgrid.getCell(rowid,'Songurl');
						schedgrid.setCell(rowid,'Songurl','<image src="'+playbutton+'" width="20px" height="15px" onclick="play_song('+songlink+')" />');
						schedgrid.hideCol('Songurl');
						storeurl = schedgrid.getCell(rowid,'storeURL');
						if(storeurl.length>1){
						schedgrid.setCell(rowid,'storeURL','<a href="'+storeurl+'" target="imradio_sub">Store</a>');
						}
						band_link = schedgrid.getCell(rowid,'Link');
						band_name = schedgrid.getCell(rowid,'Artist');
						schedgrid.setCell(rowid,'Artist','<a href="'+band_link+'"> '+band_name+' </a>');
			 }
      }
 ).navGrid('#pager1',{edit:false,add:false,del:false}).css('top',50);
}






/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/

// TODO JsDoc

/**
* Create a cookie with the given key and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
* used when the cookie was set.
*
* @param String key The key of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/

/**
* Get the value of a cookie with the given key.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String key The key of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
function change_station_button_handler_schedule(){
	jQuery('#sch_chan_button').unbind('click');
    jQuery('#sch_chan_button').click(function(){
	  schselected_gen=jQuery('#sch_gen_select').val();
	  schselected_loc=jQuery('#sch_location_select').val();
	  var mygrid = jQuery("#list1");
	  mygrid.jqGrid('setGridParam',{url:'http://www.imradio.com/views/mainparts/schedule_xml.php?l='+schselected_loc+'&g='+schselected_gen+'&first=0&localtime='+gettimeoffset()+'&page_num=2'}).trigger('reloadGrid');
    });
}
function reset_drops(selected_gen,selected_loc){
    //alert(selected_gen+selected_loc);
    location_select.val(selected_loc)
    gen_select.val(selected_gen);
}
var newtop =0;
function scroll_feature_artists(){   
    if (newtop>-2700){
        newtop = newtop - 2;
    }
    else{
        newtop = 0;
    }
    jQuery('.ourfavorite').css('top',newtop);
}
