// JavaScript Document

$(document).ready(function(){


        $(".schedule-ribbon").css('display', 'block'); 

		//document ready
	    $('#WDUN-Ribbon').bxSlider({
			mode: 'fade',
			speed: 300, 
			easing: 'swing'
		});


	
	
	//lineup
	
	$(".schedule-ribbon").css('display', 'none'); 
	
      $(".our-lineup").toggle(function(){
      		
            //Open menu            
            $(".schedule-ribbon").stop().slideDown("slow");  
	       $(".our-lineup").css('background-image', 'url("/images/nav-our-lineup-bg-001-hv-minus.jpg")');  
      }, function(){
            //Close menu    
            $(".schedule-ribbon").stop().slideUp("slow"); 
		  $(".our-lineup").css('background-image', 'url("/images/nav-our-lineup-bg-001-hv.jpg")');  
			
			
      });
      
      //initialize survey
      initHomeSurvey();
      
      //init header search bar
      initHeaderSearch();
      
      //Popup Radio Stations
     setTimeout(initRadioPopupPlayers, 1000);
	
}); //doc ready function end


/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */

/**
 * loads the homepage survey externally from:
 * http://www.accessnorthga.com/includes/ajax/survey.php
 * Sets poll into body HTML of homepage  
 */ 
function initHomeSurvey() {

	$('#pollcontainer').html( 'Loading...' );

	
	$('#pollcontainer').load('http://www.wdun.com/includes/html/ajax/anga_survey.php?id=10', function() {
	       $('#submitSurveyButton').click( submitSurvey );
	});
	

}

function submitSurvey( e ) {

     e.preventDefault();
     
	//alert(document.getElementById("survey_ans").value);
	if(valRadio(document.surveyForm.survey_ans) != null){
		//var action = document.getElementById("surveyForm").action;
		document.getElementById("surveyForm").action = 'http://www.accessnorthga.com/access/survey/index.php?m=s_detail';
		document.getElementById("surveyForm").submit();
	}else{
		alert("You must select one answer to submit the survey.");
	}
}

function valRadio(radioGroup) {
	//alert(radioGroup.value);
	//alert(radioGroup.length);
	var count = -1;
	for (var i=radioGroup.length-1; i > -1; i--) {
		//alert(radioGroup[i].checked);
		if (radioGroup[i].checked) {count = i; i = -1;}
	}
	if (count > -1) return radioGroup[count].value;
	else return null;
}


/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */


function initHeaderSearch() {
     
     var searchBox=$('input#ahq')

     searchBox.focus(function(e){            
          $(this).addClass("ahactive");
          if( $(this).attr('value') == 'Search This Site' ){
               $(this).attr('value','');
          }
          
     });
     searchBox.blur(function(e){  
          $(this).removeClass("ahactive");
          if( $(this).attr('value') == '' ){
               $(this).attr('value','Search This Site');
          }  
     });  
     
     searchBox.keypress(function(e){
          if(e.which == 13){
               submitSearchBox(e);
          }
     });

     
     $('#ahbutton').click( submitSearchBox );

}

/**
 * activate/submit search box
 */ 
function submitSearchBox(e){

     var searchBox=$('input#ahq');
     var query = searchBox.attr('value');
     query = escape( query );

     if( query != '' ) {
          window.location = '/fm/search/?query='+query;
     }

}



/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */
/* //////////////////////////////////////////////////////////// */


function initRadioPopupPlayers() {

     //radio popup players, just add CSS class
     $('a.openWDUN550').click( openWDUN550 );
     $('a.openWDUN1029').click( openWDUN1029 );
     $('a.openESNP1240').click( openESNP1240 );
     
}


function openWDUN550( e ) {
     e.preventDefault();
     //openPlayer('http://www.streamaudio.com/stations/player/pages/index.asp?Station=WDUN_AM');
     fncCenteredChildWindow( 'http://mgmt.firststreaming.com/listen/player.php?callsign=WDUN_AM', 375, 648,'no','no');
}

function openWDUN1029( e ) {
     e.preventDefault();
     //openPlayer('http://www.streamaudio.com/stations/player/pages/index.asp?Station=WMJE_FM');
     fncCenteredChildWindow( 'http://mgmt.firststreaming.com/listen/player.php?callsign=WDUN_FM', 375, 648,'no','no');
}

function openESNP1240( e ) {
     e.preventDefault();
     //fncCenteredChildWindow( 'http://mediasuite.multicastmedia.com/playerlive.php?e=lxe861s6&doResize=false', 275, 325,'no','no');
     fncCenteredChildWindow( 'http://www.streamaudio.com/player/player.aspx?optin=no&station=WDUN_IR', 275, 325,'no','no');
}

function fncCenteredChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=no')
}


/*
StreamAudio Player Open Script
*/

 function openPlayer(URL) {
     if(navigator.appVersion.indexOf("AOL") > -1)
      {
      //AOL
      var opt1 = 'width=472,height=257';
      var opt2 = 'width=472,height=257';
      } else if(navigator.platform.indexOf("Win") > -1)
      {
      //IE and NS Windows
      var opt1 = 'width=472,height=257,top=420,left=520,screenY=420,screenX=520';
      var opt2 = 'width=472,height=257,top=250,left=300,screenY=250,screenX=300';
      } else if(navigator.platform.indexOf("Mac") > -1)
      {
      //IE and NS Mac
      if(navigator.appName.indexOf("Microsoft") > -1)
      {
      var opt1 = 'width=455,height=240,top=420,left=520,screenY=420,screenX=520';
      var opt2 = 'width=455,height=240,top=250,left=300,screenY=250,screenX=300';
      } else if(navigator.appName.indexOf("Netscape") > -1)
      {
      var opt1 = 'width=472,height=257,top=420,left=520,screenY=420,screenX=520';
      var opt2 = 'width=472,height=257,top=250,left=300,screenY=250,screenX=300';
      }
      }
    if(screen.width >= 1000) {
          window.open(URL,'Streamaudio_Player',opt1);
     } else {
          window.open(URL,'Streamaudio_Player',opt2);
     }
}
