 var newMusicArray;
 var newsArray;
 var offset=0;
 var isColapsed = false;
 var subscriberInfo = new Object();
 
 
 function initIndexPage(){
 
 
      
     
      jQuery.noConflict();
      jQuery(document).ready( function(){
      
      
     
     
       jQuery("#newEntries").css({
                                   "background":"#ffffff",
                                   "border":"1px solid #cccccc",
                                   "width":"800px", 
                                   "height":"120px"  });
                                  
       jQuery("#newEntries").addClass("ui-corner-all");
       jQuery("#newEntries").prepend("<a href=\"javascript:colapseNewEntries()\" class=\"ui-icon ui-icon-triangle-1-n\"></a><a href=\"javascript:expandNewEntries()\"  class=\"ui-icon ui-icon-triangle-1-s\"></a>" );          
       printNewEntriesPage(1) ;
       setNewMusic();
       jQuery("#dialog").append("<h2>Please wait, while redirected</h2>");
      // jQuery("#dialog").dialog({modal:true });
       jQuery("#dialog").css( {"position":"absolute",
                               "top":"150px",
                               "left":"200px",
                               "background":"#ffffff",
                               "width":"350px",
                               "height":"250px",
                               "border":"1px solid #cccccc",
                               "z-index":"300",
                               "opacity":"0.1"   } );
                               
                               
       
      
                                                                                  
                                              
       jQuery("#musicSearchForm button").click( function(){   goSearch();  }     ); 
       jQuery("#musicSearchForm button").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
       		                                function(){  jQuery(this).removeClass("ui-state-hover");     }   );//end hover
	 
	
         
       
        jQuery("#newMusicButton").click( function(){   loadNewEntries();  } ); //end click
	                                                  
	       
	jQuery("#newMusicButton").hover( function(){  jQuery(this).addClass("ui-state-hover");      },
		                         function(){  jQuery(this).removeClass("ui-state-hover");   }     );//end hover
	 
      
 
 					} );//end document ready
 
 
          jQuery("#downloadButton button").css({  "width":"100px","height":"25px"  });
          jQuery("#downloadButton button").addClass(   "ui-state-default"           );
          jQuery("#downloadButton button").addClass(   "ui-corner-all"              );
           
          jQuery("#downloadButton button").click( function(){
                                                                alert("download");
                                                                downloadBMP();
                                                         
                                                         
                                                                           } );
                                                                           
                                                                           
         jQuery("#downloadButton button").hover( function(){  jQuery(this).addClass("ui-state-hover"); },
		                                 function(){  jQuery(this).removeClass("ui-state-hover");     }     );//end hover
	                                                                 
          
          
                                                 
           
 }//end initPage 
 
 
 
 function printNewEntriesPage(){
   
   
    
     var pageHTML = 
    
     "<div id=\"entriesLabel\">New Entries<div>"+ //label end
    "<div id=\"entriesTable\" "+
    "          style=\"width:800px;"+
    "          position:relative;  "+
    "          height:100px\">"+   
    "<div id=\"musicPages\">"+
    "<a href=\"javascript:printNewMusic(1)\">&nbsp;1&nbsp;</a>"+
    "<a href=\"javascript:printNewMusic(2)\">&nbsp;2&nbsp;</a>"+
    "<a href=\"javascript:printNewMusic(3)\">&nbsp;3&nbsp;</a>"+
    "<a href=\"javascript:printNewMusic(4)\">&nbsp;4&nbsp</a>"+
    " </div>"+
    
   "</div>"; //table end
   
    jQuery("#errorMesssage").remove();
    jQuery("#newEntries").append( pageHTML );
   

    
     jQuery("#entriesLabel").css({  "color":"#999999",
                                    "font-family":"tahoma",
                                    "font-size":"12pt"});
                               
     jQuery("#musicPages").css({ "width" :"700px",
                                 "height":"60px",
                                 "left"  :"40px",
                                 "z-index":"150"  });
                               
      jQuery("#musicPages a").css({ "color":"#cccccc",
                                    "width":"60px",
                                    "height":"60px",
                                    "border":"1px solid #cccccc" }); 
                               
                        
                                
     jQuery("#musicPages a").hover( function(){ jQuery(this).css({ "color":"green", "border":"1px solid green"} );   },
                                    function(){ jQuery(this).css({ "color":"#cccccc", "border":"1px solid #cccccc" } ); }  ); //hover
   
   
    
   }
   
 
 


 
 
 function colapseNewEntries(){
 
  	if( !isColapsed){
    
    		//jQuery("#entriesTable").toggle("up");
    		jQuery("#newEntries").toggle("up");//animate( {"height":"40px"},1000 );
    		//jQuery("#header").animate( {"height":"235px"},2000 );
    
   	}
 
 }
 
 
 function expandNewEntries(){
 
    
   	if( isColapsed ){
   
     		//jQuery("#entriesTable").toggle("down");
     		jQuery("#newEntries").toggle("down");//animate( {"height":"120px"},1000 );
     		//jQuery("#header").animate( {"height":"350px"},2000 );
     
     	}
 }
 


function getRandomIndex( maxNumber ){



  index = Math.round( Math.random()*maxNumber ) ;
  return index;
       


}


function getNewsArray(){


	return this.newsArray;  

}






function setNewMusic(){


        
	
	  var pageUrl="/php/newEntriesProxy.php";
	 
	  jQuery("#newEntries").append("<div id=\"errorMessage\" style=\"background:#ffffff\">Please wait, loading, new entries...</div>");
		
			jQuery.ajax({
			
			  
			  url: pageUrl,
			  cache: false,
			  async: false,
			  dataType:"xml",
			  success: function( xmlText, success ){
			    
			   
			    setNewMusicArray( xmlText );
			    printNewMusic(1);
			    
			    
			    
			  },//end success.
			  error: function (XMLHttpRequest, textStatus, errorThrown) {
			  
			       jQuery("#errorMessage").children().remove();
			       jQuery("#errorMessage").text("Error loading entries. Reload page please!");
			    
                          }
			  
			  
			  
		});//rnd ajax


	





}//end function







function setNewMusicArray( xmlText ){


    this.newMusicArray = new Array();
    jQuery( xmlText ).find("album").each( function(){
    
    	  	
	  	        var ID = jQuery(this).children( "id").text();
	  	        var icon = jQuery(this).children( "icon").text();
	  	        var albumName= jQuery(this).children("albumName").text();
	  	        var performerName = jQuery(this).children("performerName").text();
	  	        var albumObject = { id:ID, icon:icon, albumName:albumName, performerName:performerName };
	  	        
  	                addAlbumToMusicArray( albumObject );
  	        
  	                                                      }   );//end each


}



function printNewMusic( page ){

  
      //4 albums on page
  	var lowIndex = new Number( (page-1)*5 );
  	var highIndex =new Number( page*5 );
 	  	
  	  	
  	
  	var tableHTML = "<div id=\"allAlbums\" style=\"float:left; margin-left:100px; margin-top:-110px;width:850px\">";
  	  
  	for( var i= lowIndex; i< highIndex; i++ ){
  	
  	        var ID = this.newMusicArray[i].id;
  	        var icon = this.newMusicArray[i].icon;
  	        var albumName= this.newMusicArray[i].albumName;
  	        var performerName = this.newMusicArray[i].performerName;
  	        
  	        tableHTML+="<div name=\"entry"+ i+"\" style=\"float:left;margin:5px\">"+
  	                   "<a  href=\"javascript:goAlbum('"+ID+"','"+performerName+"','"+ albumName.replace("'","\\'") +"')\">"+
                           "<img src=\""+icon+"\" width=\"100\"></a>"+
                            "</div>" ;
  	                                         
  	  
  		
  	}//end for
  	
  	  tableHTML += "</div>";
        
      
        jQuery("#allAlbums").remove();
     
        jQuery("#entriesTable").append( tableHTML );
        jQuery("#allAlbums").animate({"opacity":"0.3"},1000 );
        jQuery("#allAlbums").animate({"opacity":"1"},1000 );
  	jQuery("#errorMessage").remove();                                             
  	                                                  
  
}//function printNewMusic









function addAlbumToMusicArray( albumObject ){

   
   this.newMusicArray.push( albumObject );


}




function setNews( number ){


        
	 
	  
	  var pageUrl="/php/newsProxy.php";	                   
	  
	  jQuery("#newsContent").append("<div>loading , please wait...</div>");
	 
	  
	
		
			jQuery.ajax({
			
			  
			  url: pageUrl,
			  cache: false,
			  async: false,
			  dataType:"xml",
			  success: function( xml, success ){
			    
					   
			    setNewsArray( xml );
			    printNews( number );
			    
			    
			    
			  },//end success.
			  error: function (XMLHttpRequest, textStatus, errorThrown) {
			  
			      jQuery("#newsContent").append("<div>loading , please wait...</div>");
			    
                          }
			  
			  
			  
		});//rnd ajax


	





}//end function




function setNewsArray( xmlText ){

     this.newsArray = new Array();
     var item = jQuery(xmlText).find('item').each( function(){
     
                
  			   
  	                  var title =       jQuery(this).children("title").text();
  	                  var description = jQuery(this).children("description").text();
	  	          var link=         jQuery(this).children("link").text();
	  	          var newsObject = { title:title, description:description,link:link };        
  	                  
  	                  newsArrayAddNews(   newsObject );
  	        
  	  }  );//end each
                            


}//end setNewsArray

function newsArrayAddNews( newsObject ){


   this.newsArray.push( newsObject );


}


function printNews( number ){

       var daysArray = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
       var monthsArray=["Jannuary","February","March","April","May","June","July","August","September","October","November","December"];
      //4 albums on page
  	var dateObject=new Date();
  	var day = dateObject.getDay();
  	var date = dateObject.getDate();
  	var month = dateObject.getMonth();
  	var year = dateObject.getFullYear();
  	
  	var today = daysArray[day]+", "+monthsArray[month]+" "+date+", "+year;
  	var resHTML = "<h3>Headlines "+  today+"</h3>"+
  	              "<div id=\"news\"></div>"+
  	              "<div id=\"newsItem\"></div>";
  	              
	                	      
  	jQuery("#newsContent").children().remove();
  	jQuery("#newsContent").append( resHTML );
  	
  	
  	var allNews ="";
  	var size= new Number( number );
  	
  	for( var i=0; i< this.newsArray.length; i++ ){
  	
  	        var title = this.newsArray[i].title;
  	        var description = this.newsArray[i].description;
  	        var link= this.newsArray[i].link;
  	        
  	        
  	        allNews+=  description;
  	                    //widget
  	                  /*"<a class=\"greenLink\" title=\""+ description+"\" style=\"text-decoration:underline\" name=\""+i+"\" >"+title+"</a>"+
  	                  "<br>"+
  	                  "</div>";//widget end*/
  	       
  		
  	}//end for
  	
  	
  	
  	
  	jQuery("#news").append( allNews );
  	/*jQuery("#news a").click(  function(){ 
  	                                         
  	                                          
  	                                          var newsObject = getNewsArray()[ jQuery(this).attr("name")];
  	                                          var newsItemHTML =  
  	                                                              "<div class=\"ui-widget content\" style=\"margin:5px; font-family:times\">"+
  	                                                                newsObject.description+"<br>"+
  	                                                              "<a href=\"javascript:goLocation('"+newsObject.link+"','"+newsObject.title.replace("\'","\\\'")+"')\" >more...</a>"+
  	                                                              "</div>";
  	                                                               
  	                                                 jQuery("#newsDialog").html( newsItemHTML);
  	                                                
  	                                                 setLinksClass("#newsDialog a","green");
  	                                                 jQuery("#newsDialog").dialog( 'open' );
  	                                                 
  	                                                 
  	                                                 } );// end click	                                      
  	                                      
  	                */                        	
  	                                      
 	
                                                                                                                                            
		setLinksClass("newsDialog a", "green")	    			       
			    
  
}//end printNews



function setLinksClass( selector, color ){                                                                                                 
                                                                                                        
        jQuery(selector).css({"color":color,"opacity":"0.6"});
	jQuery(selector).hover(      function(){ 
			    			             jQuery(this).css({"opacity":"1"});
                                                             jQuery(this).animate({ opacity:"0.1"},1000 );
                                                             jQuery(this).animate({ opacity:"1"},1000 );
                                                             
                                                             },
			    			           
			    	      function(){ 
			    			                                             
			    			             jQuery(this).css( {"opacity":"0.8" });
			    			             jQuery(this).stop();
			    			                                                         
			    			    }   );//end hover                                                                                               
			    			       
			    
			    
			    
			    
	
 }//end function                                              




function goNews( link){



var newWindow = window.open();
    newWindow.location=link;



}

function goLocation( location, googleKeyword){

	
	var newWindow = window.open();
	    newWindow.document.write("<html><head><title>"+googleKeyword+"+</title></head>"+
	                                "<frameset rows=\"200,*\" style=\"border:1px solid orange\" frameborder=\"no\">"+
	                                "<frame name=\""+googleKeyword+"\" src=\"http://www.ballroomLibrary.com/googleAdds.html\">"+
	                                "<frame name=\"main\" src=\""+location +"\">"+
	                                "</frameset>"+
	                              "</html>");
	  
  
	  	//jQuery("#newsDialog").dialog('close');


}


function goBlog(){

 var newWindow = window.open();
     newWindow.location = "http://ballroomRadio.com/blog/online_help";
}

function goHome(){
     location="index.html"
}
function goRadio(){
     //location="http://www.ballroomradio.com"
     location="announcement/radioDown48.html"
}

function goLogin(){
    //location="/announcement/anouncement.html";
    location="registeredUserLogin.html"
}

function goPublisherLogin(){
    //location="/announcement/anouncement.html";
    location="publisherLogin.html"
}

function goRegister(){

     location="http://www.ballroomlibrary.com/registerFreeUSListenerBeta.html"
}


function goDance( dance ){

 var newWindow = window.open();
    newWindow.location="http://www.ballroomlibrary.com/radioinfoserver/PrintDanceServlet?page=1&userName=anonymous&dance="+dance+"&subscription=anonymous";
}

function goPerformer( lastname ){

  goLocation( "http://www.ballroomlibrary.com/radioinfoserver/FindPerformerServlet?lastName="+lastname+"&userName=anonymous&subscription=none&page=1", "Albums by: "+lastname  );
  
  
}

function goAlbum( albumId ,performer,albumName ){

  
  goLocation( "http://www.ballroomlibrary.com/radioinfoserver/PrintAlbumServlet?userName=anonymous&subscription=none&albumID="+albumId+"\"","album "+albumName+"from performer "+performer );
    
 
  
     
}

function goSearch(){

	var newWindow = window.open();
	newWindow.location="http://www.ballroomlibrary.com/managelistserver/PrintLibraryManagerServlet?userName=anonymous&subscription=none";

}


function goBallroomPlayer(){
  var newWindow = window.open();
      newWindow.location="/studioPlayer/index.html";
}
function goSongByPerformer( id ){

  var newWindow = window.open();
      newWindow.location="http://www.ballroomlibrary.com/radioinfoserver/FindSongByPerformerServlet?performerID="+id+"&userName=anonymous&subscription=none&page=1";
}


function goTitle( form ){

 var word = form.queryField.value;

   var newWindow = window.open();
   newWindow.location="http://www.ballroomlibrary.com/radioinfoserver/PrintSongsByTitleServlet?title="+word+"&userName=anonymous&subscription=none&page=1";
}

function menuSearch( subject ){

	if ( subject = "books" ){

   		var newWindow = window.open();
   		newWindow.location="http://click.linksynergy.com/fs-bin/click?id=dxgn2OfPiOA&offerid=99238.556415&type=10&subid=0&tmpid=939&RD_PARM1=http%253A%252F%252Fwww.alibris.com/search/search.cfm%253FS%253DR%2526wtit%253DBallroom%2520Dancing%2526"

	}// if

}// end function

function searchWord( keyword ){

        var locUrl = "http://www.google.com/custom?domains=designers.ballroomdress.us&q="+keyword+"&sa=Search&sitesearch=&client=pub-3837358447107106&forid=1&ie=ISO-8859-1&oe=ISO-8859-1&safe=active&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A1%3B&hl=en";

   		newWindow=window.open();
   		newWindow.location=locUrl ;
 }
 
 function describePlan( plan ){
 
 	var newWindow;
   	 	
   	 	if( plan=="basic"){
   	 	
   	 	        
   	 	        newWindow = window.open("","","width=500,height=500");
   	 	 	newWindow.document.write("<html><title>Subscription plan - Personal Basic</title><head></head><body>"+
   	 	 	                         "<h3>Subscription plan: Personal basic</h3>"+
   	 	 	                         "<li>Free account</li>"+
   	 	 	                         "<li>Access to all songs</li>"+
   	 	 	                         "<li>Free audio samples ( restricted to 30 s )</li>"+
   	 	 	                         "<li>Free personal lists</li>"+
   	 	 	                         "</body></html>" );
   	 	 	                          
   	 	 	
   	 	 }
   	 	 else if( plan=="premium" ){
   	 	     
   	 	      
   	 	         var newWindow = window.open("","","width=500,height=500");
   	 	 	 newWindow.document.write(
   	 	 	 			"<html><title>Subscription plan - Personal Premium</title><head></head><body>"+							
   	 	 	                          "<h3>Subscription plan: Personal premium</h3>"+
   	 	 	                         "<li>Free account</li>"+
   	 	 	                         "<li>Access to all songs</li>"+
   	 	 	                         "<li>Free audio samples ( full length )</li>"+
   	 	 	                         "<li>Free personal lists</li>"+
   	 	 	                         "<li>Free personal radio station</li>"+
   	 	 	                          "</body></html>" );
   	 	 	                          
   	 	 	
   	 	 	}
   	 	 else if( plan=="studio" ){
   	 	  
   	 	  	
   	 	         var newWindow = window.open("","","width=500,height=500");
   	 	 	newWindow.document.write(
   	 	 				 "<html><title>Subscription plan - Studio</title><head></head><body>"+
   	 	 	                         "<h3>Subscription plan: Studio</h3>"+
   	 	 	                         "<li>Free account</li>"+
   	 	 	                         "<li>Free Studio Player Software</li>"+
   	 	 	                         "<li>Access to all songs</li>"+
   	 	 	                         "<li>Unlimited Music On Demand</li>"+
   	 	 	                         "<li>Free personal premium subscription</li>"+
   	 	 	                          "</body></html>" );
   	 	 	
   	 	}
   	 	else if( plan=="trial" ){
   	 	
   	 	        var newWindow = window.open("","","width=500,height=500");
   	 	
   	 		newWindow.document.write(	"<html><title>Subscription plan - Studio TRIAL</title><head></head><body>"+
   	 		                                                 "<h3>Subscription plan: Studio</h3>"+
			   	 	 	                         "<li>Free account</li>"+
			   	 	 	                         "<li>Free Studio Player Software</li>"+
			   	 	 	                         "<li>Access to all songs</li>"+
			   	 	 	                         "<li>Unlimited Music On Demand</li>"+
			   	 	 	                         "<li>Free personal premium subscription</li>"+
			   	 	 	                         "<li>30 days only</li>"+
			   	 	 	                           "</body></html>");
   	 	 	
   	 	 	
   	 	 	
   	 	 	}//end if
   	 	 	
   	 	 	else{}
 
 }//end function



function redirectURL( siteUrl){

    
 
       jQuery("#dialog").fadeTo( "slow",1 );
       document.location.href= siteUrl;
   
   
 }



function downloadBMP(){

   alert("download");
   var newWindow = window.open();
       newWindow.location.href= "/softwareDownloads/BallroomMusicPlayer/index.html";



}
