var Event = YAHOO.util.Event,Dom = YAHOO.util.Dom;
var dialog,calendar;

$(document).ready(
	function() {
		$("#week").paginate({
		recordsPerPage: 25
		});
		$("#year").paginate({
		recordsPerPage: 25
		});
		$("#search").paginate({
		recordsPerPage: 20
		});
    var showBtn = Dom.get("show");
    Event.on(showBtn, "click", function() {

        if (!dialog) {

                // Hide Calendar if we click anywhere in the document other than the calendar
                Event.on(document, "click", function(e) {
                    var el = Event.getTarget(e);
                    var dialogEl = dialog.element;
                    if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
                        dialog.hide();
                    }
                });
                function closeHandler() {
                    dialog.hide();
                }
                dialog = new YAHOO.widget.Dialog("container", {
                    visible:false,
                    context:["show", "tl", "bl"],
                    buttons:[ {text:"Close", handler: closeHandler}],
                    draggable:false,
                    close:true
                });
                dialog.setHeader('Pick A Date');
                dialog.setBody('<div id="cal"></div>');
	   var cnt = Dom.get("CalContain");
                dialog.render(cnt);

                dialog.showEvent.subscribe(function() {
                    if (YAHOO.env.ua.ie) {
                        // Since we're hiding the table using yui-overlay-hidden, we 
                        // want to let the dialog know that the content size has changed, when
                        // shown
                        dialog.fireEvent("changeContent");
                    }
                });
            }
            if (!calendar) {

                calendar = new YAHOO.widget.Calendar("cal", {
                    iframe:false,          // Turn iframe off, since container has iframe support.
                    hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
                });
                var dField = Dom.get("hWeek");
                calendar.select(dField.value);
                calendar.render();

                calendar.selectEvent.subscribe(function() {
                    dialog.hide();
                    if (calendar.getSelectedDates().length > 0) {
                        var selDate = calendar.getSelectedDates()[0];
                        dField.value=(selDate.getMonth()+1) + "/" + selDate.getDate() + "/" + selDate.getFullYear();
                        $("#fWeek").submit();
                        // Pretty Date Output, using Calendar's Locale values: Friday, 8 February 2008
                        //var wStr = calendar.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
                        //var dStr = selDate.getDate();
                        //var mStr = calendar.cfg.getProperty("MONTHS_LONG")[selDate.getMonth()];
                        //var yStr = selDate.getFullYear();
        
                        //Dom.get("date").value = wStr + ", " + dStr + " " + mStr + " " + yStr;
                    } 
                });

                calendar.renderEvent.subscribe(function() {
                    // Tell Dialog it's contents have changed, which allows 
                    // container to redraw the underlay (for IE6/Safari2)
                    dialog.fireEvent("changeContent");
                });
            }

            var seldate = calendar.getSelectedDates();

            if (seldate.length > 0) {
                // Set the pagedate to show the selected date if it exists
                calendar.cfg.setProperty("pagedate", seldate[0]);
                calendar.render();
            }
            dialog.show();

      }
    );
	}
);
function getmusic(songid,title,artist)
{
  var url = "/music/detail/" + songid + "/?width=500";
  if(typeof(_gaq)!="undefined")
    _gaq.push(['_trackEvent','Music', 'Preview/Buy', title + " by " + artist]);
  tb_show(title + " by " + artist, url, false);
  $("#TB_window").bind("unload",function(){
    var g = $("#musicpreview")[0];
    g.stopSong();
  }
  );

return false;
}
    function playPreview(songid) {
    	var g = $("#musicpreview")[0];
    	if(g.getCurrent()==songid)
    	{
    		if(g.isSongPlaying())
    			g.pause();
    		else
    			g.resume();
    	}
    	else
      {
          if(typeof(_gaq)!="undefined")
            _gaq.push(['_trackEvent','Music', 'Play Preview', songid + '|' + $("#" + songid +" div.details > a").text() + ' ' + $("#" + songid +" div.details > div.artist").text()]);
        	g.playSong(songid);
      }
    }
    function onStop(songid)
    {
      var mp = $("#" + songid + " img.musicprev");
    	mp.attr("src","http://content.skalooza.com/chrome/play.gif");
      mp.parent("a")[0].lastChild.data=" Play Preview";
    }
    function onPlay(songid)
    {
      var mp = $("#" + songid + " img.musicprev");
    	mp.attr("src","http://content.skalooza.com/chrome/pause.gif");
      mp.parent("a")[0].lastChild.data=" Pause Preview";
    } 

var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 124;
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
	// DO NOT MODIFY THE FOLLOWING FOUR LINES
	// Location visited after installation is complete if installation is required
	var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
	var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

	AC_FL_RunContent(
		"src", "playerProductInstall",
		"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
		"width", "1",
		"height", "1",
		"align", "middle",
		"id", "musicpreview",
		"quality", "high",
		"bgcolor", "#FFFFFF",
		"name", "musicpreview",
		"allowScriptAccess","sameDomain",
		"type", "application/x-shockwave-flash",
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
} else if (hasRequestedVersion) {
	// if we've detected an acceptable version
	// embed the Flash Content SWF when all tests are passed
	AC_FL_RunContent(
			"src", "musicpreview",
			"width", "1",
			"height", "1",
			"align", "middle",
			"id", "musicpreview",
			"quality", "high",
			"wmode","transparent",
			"bgcolor", "#FFFFFF",
			"name", "MusicPreview",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
  	+ 'This content requires the Adobe Flash Player. '
   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }

