// Start playing a music video, shut down radio (if possible), set playlist highlight structure, change license plate
function playVideo(videoId, vimeoId, iTunesLink) {
    if (typeof popupWin != 'undefined') {
    if(false == popupWin.closed) 
    {
        popupWin.close ();
    }
    }
    
    if (typeof videoId != 'undefined')  {
    var rowName = ('i' + videoId);
	var targetId=document.getElementById('videostage');
    var rowId=document.getElementById(rowName);
	targetId.innerHTML='<iframe src="http://player.vimeo.com/video/'+vimeoId+'?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="452" height="265" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'
	var tr=rowId;
	var table=document.getElementById('pltable');
	var rows = table.getElementsByTagName("tr");
	for(i = 0; i < rows.length; i++) {
	rows[i].style.backgroundImage = '';
	}
	tr.style.backgroundImage = 'url(../images/plselect.png)';
    
    //Pop iTunes share link

	var fbTargetId=document.getElementById('fblink');
	fbTargetId.innerHTML='<iframe src="//www.facebook.com/plugins/like.php?href=www.on-airstreaming.com%2Fvideos%2Findex.php%3Fvid%3D'+ videoId +'&amp;send=false&amp;layout=button_count&amp;width=100&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>';
	var itlTargetId=document.getElementById('ituneslink');
    if (iTunesLink != 'none') {
        itlTargetId.innerHTML='<a href="http://click.linksynergy.com/fs-bin/stat?id=NYEek7o51yY&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fitunes.apple.com%252Fus%252Fartist%252F'+ iTunesLink +'%253Fuo%253D4%2526partnerId%253D30" target="itunes_store"><img src="http://www.on-airstreaming.com/images/itunesvid.png" style="border: 0;" /></a>';
    }
    else {
        itlTargetId.innerHTML='';
    }

   return false;
}}


// Start playing an interview, shut down radio (if possible), set playlist highlight structure, change license plate
function playIntVideo(videoId, vimeoId) {
    
    if (typeof popupWin != 'undefined') {
    if(false == popupWin.closed) 
    {
        popupWin.close ();
    }
    }
    if (typeof videoId != 'undefined')  {
	var targetId=document.getElementById('videointstage');
    var rowName = ('i' + videoId);
    var rowId=document.getElementById(rowName);

    targetId.innerHTML='<iframe src="http://player.vimeo.com/video/'+vimeoId+'?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="452" height="265" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'

	var tr=rowId;
	var table=document.getElementById('pltable');
	var rows = table.getElementsByTagName("tr");
	for(i = 0; i < rows.length; i++) {
	rows[i].style.backgroundImage = '';
	}
	tr.style.backgroundImage = 'url(../images/plselect.png)';
   return false;
}}

//
function openRadio() {
	var targetId=document.getElementById('videostage');
    if (targetId != null)
    {
		targetId.innerHTML="";
    }
    var targetIntId=document.getElementById('videointstage');
    if (targetIntId != null)
    {
		targetIntId.innerHTML="";
    }

	popupWin = window.open('../oasradio','radio','dependent, width=368, height=207, left=0, top=0');
 }


// Quick generic form field validator
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

//Validate the contact form items and submit
function validate_form(thisform)
{
with (thisform)
  {
  if (validate_required(q0_ContactPurpose,"You forgot to tell us what you want!")==false)
  {q0_ContactPurpose.focus();return false;}
  if (validate_required(q1_Name,"You forgot to tell us your name!")==false)
  {q1_Name.focus();return false;}
  if (validate_required(q2_Email,"You forgot to tell us your email address!")==false)
  {q2_Email.focus();return false;}
  if (validate_required(q5_Message,"You haven't written a message yet!")==false)
  {q5_Message.focus();return false;}
  }
}

//Validate the share video form items and submit
function validate_videoform(thisform)
{
with (thisform)
  {
  if (validate_required(to,"You forgot to tell us who you want to send this to!")==false)
  {q0_ContactPurpose.focus();return false;}
  if (validate_required(message,"You forgot to type a message!")==false)
  {q1_Name.focus();return false;}
  if (validate_required(userFromName,"You forgot to tell us your name!")==false)
  {q2_Email.focus();return false;}
  if (validate_required(userFromEmail,"You forgot to enter your email address!")==false)
  {q5_Message.focus();return false;}
  else {
  thisform.submit();
  }
  }

}

    
// Populate the Music Videos Playlist from XML
function popMVidPl()

{
    if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        var xmlhttp=new XMLHttpRequest();
    }
    else
        {// code for IE6, IE5
        var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","../pl/plvids.xml",false);
    xmlhttp.send('oas');
    var xmlDoc=xmlhttp.responseXML; 
       
    if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
 		 document.write ('<div id="plscrollwrap"><div id="pliwindow">');
	 }
     else {
        document.write ('<div id="plwindow">');
        }
        
    document.write('<table id="pltable">');
    var x=xmlDoc.getElementsByTagName("video");

    for (i=0;i<x.length;i++)
        { 
        if (x[i].getAttribute("active") == "1") {
            document.write ('<tr class="plrow" id="i' +  x[i].getAttribute("id") + '">');
            document.write ('<td class="thumb" onclick="window.open(\'http://www.on-airstreaming.com/videos?vid='+ x[i].getAttribute("id") + '\',\'_self\');"><img src="../images/vidthumbs/' + x[i].getAttribute("id") + '.jpg" class="vidimgthumb"></td>');
            document.write ('<td class="artistinfo"><span onclick="window.open(\'http://www.on-airstreaming.com/videos?vid='+ x[i].getAttribute("id") + '\',\'_self\');">' + x[i].getAttribute("artist") + '<br>"' + x[i].getAttribute("song") + '"</span><br><a href="http://' + x[i].getAttribute("website") + '" target="_blank">' + x[i].getAttribute("website") + '<a></td>');
            document.write('</tr>');
        }
        }
    document.write('</table>');

    if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
        document.write('</div></div>');
        var myScroll = new iScroll('pliwindow', { fadeScrollbar:false });
	 }
     else {
     document.write('</div>');
     }
    
}

// Populate the Artist Interviews Playlist from XML
function popIntVidPl()
{
    if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        var xmlhttp=new XMLHttpRequest();
    }
    else
        {// code for IE6, IE5
        var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET","../pl/plints.xml",false);
    xmlhttp.send('oas');
    var xmlDoc=xmlhttp.responseXML; 
    
    if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
 		 document.write ('<div id="plscrollwrap"><div id="pliwindow">');
	 }
     else {
        document.write ('<div id="plwindow">');
        }
        
    document.write('<table id="pltable">');
    var x=xmlDoc.getElementsByTagName("video");

    for (i=0;i<x.length;i++)
        { 
        if (x[i].getAttribute("active") == "1") {
            document.write ('<tr class="plrow" id="i' + x[i].getAttribute("id") + '">');
            document.write ('<td class="thumb" onclick="window.open(\'http://www.on-airstreaming.com/artists?vid='+ x[i].getAttribute("id") + '\',\'_self\');"><img src="../images/vidthumbs/' + x[i].getAttribute("id") + '.jpg" class="vidimgthumb"></td>');
            document.write ('<td class="artistinfo"><span onclick="window.open(\'http://www.on-airstreaming.com/artists?vid='+ x[i].getAttribute("id") + '\',\'_self\');">Interview w/ ' + x[i].getAttribute("artist") + '</span><br><a href="http://' + x[i].getAttribute("website") + '" target="_blank">' + x[i].getAttribute("website") + '<a></td>');
            document.write('</tr>');
        }
        }
    document.write('</table>');
    
    if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
        document.write('</div></div>');
        var myScroll = new iScroll('pliwindow', { fadeScrollbar:false });
	 }
     else {
     document.write('</div>');
     }
    
}

// Add scroll functionality to playlist windows on mobile devices
function invokeScroll() {
    var myScroll = new iScroll('blogicontent', { fadeScrollbar:false });
}


// Change active tab in top nav                           
function changeid(activeid, newid) {
     document.getElementById(activeid).id = newid;
  
 }
 
// Verify contact information before submit
function contactverify() {
	var purpose = document.contact.contactpurpose;
	var name = document.contact.name;
	var email = document.contact.email;
	var phone = document.contact.phone;
	var source = document.contact.source;
	var message = document.contact.message;
	
	if (purpose.value == "none")
	{
		window.alert("Please tell us what you want!");
		document.contact.contactpurpose.focus();
		return false;
	}
	
	else if (name.value == "")
	{
		window.alert("Please enter your name.");
		document.contact.name.focus();
		return false;
	}
	else if (email.value == "")
	{
		window.alert("Please enter a valid e-mail address.");
		document.contact.email.focus();
		return false;
	}
	else if (email.value.indexOf("@", 0) < 0)
	{
		window.alert("Please enter a valid e-mail address.");
		document.contact.email.focus();
		return false;
	}
	else if (email.value.indexOf(".", 0) < 0)
	{
		window.alert("Please enter a valid e-mail address.");
		document.contact.email.focus();
		return false;
	}
	
	else if (source.value == "none")
	{
		window.alert("Please tell us how you heard about On-Airstreaming.");
		document.contact.source.focus();
		return false;
	}
	else if (message.value == "")
	{
		window.alert("Please enter a message.");
		document.contact.message.focus();
		return false;
	}
				
	return true;
	
}





// Setup sharing overlay
$(function() {


	// setup overlay
	$("#overlayButton").overlay({

		// use the Apple effect for overlay
		effect: 'apple',		
		expose: "#567",
		
		onBeforeLoad: function() {
			$f().hide().pause();
		},

		onClose: function() {
			$f().show().resume();
			$("#info").hide();
		}

	});

	// initialize tabs
	$("#shareTabs").tabs("#panes > div");

});      

// This is used to bring the playlist thumbs to 75% at page load, and to 100% on hover
$(document).ready(function(){
						   $(".vidimgthumb").fadeTo(0, 0.75); 
						   $(".vidimgthumb").hover(function(){
						   $(this).fadeTo(250, 1.0);
						   },function(){
						   $(this).fadeTo(250, 0.75);
						   });
						   });              








    








