<!--
     // Date Script by Cresk Design - Copyright 2002.

	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000) year+=1900;

	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()

	if (daym < 10)
		daym=""+daym
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

        end = "th";
        if (day==1 || day==21 || day==31) end="st";
        if (day==2 || day==22) end="nd";
        if (day==3 || day==23) end="rd";
        daym+=end;

     function WriteDate()   {
	document.write(dayarray[day]+" "+montharray[month]+" "+daym+" "+year);
}

function openPop(theURL,winName,features) {
  window.open(theURL,winName,features);
}

// Input focus Script by Cresk Design - Copyright 2007.

// get & loose HTML text input field values

function getFocus() {
  document.searchCat.track.value = "";
}

function loseFocus() {
  document.searchCat.track.value = "Search catalogue";
}



function tag_track(TrackID)
{
	document.getElementById('loading_' + TrackID).style.display = 'inline';
	jx.load('/tagit.php?fetch=true&format=json&id='+TrackID,function(data){
	
		document.getElementById('loading_' + TrackID).style.display = 'none';
		document.getElementById('taglink_' + TrackID).style.display = 'none';
		document.getElementById('untaglink_' + TrackID).style.display = 'inline';
		document.getElementById('tagimg' + TrackID).src = '/g/iuntag.png';
		
		//alert(data.tag_status);
	
	},'json','get');
	
}

function untag_track(TrackID)
{
	document.getElementById('loading_' + TrackID).style.display = 'inline';
	jx.load('/untagit.php?fetch=true&format=json&id='+TrackID,function(data){
	
		document.getElementById('loading_' + TrackID).style.display = 'none';
		document.getElementById('taglink_' + TrackID).style.display = 'inline';
		document.getElementById('untaglink_' + TrackID).style.display = 'none';
		document.getElementById('tagimg' + TrackID).src = '/g/itag.png';
		
		//alert(data.tag_status);
	
	},'json','get');
	
}



function untag_track_hide(TrackID)
{
	document.getElementById('loading_' + TrackID).style.display = 'inline';
	jx.load('/untagit.php?fetch=true&format=json&id='+TrackID,function(data){
	
		document.getElementById('loading_' + TrackID).style.display = 'none';
		document.getElementById('taglink_' + TrackID).style.display = 'inline';
		document.getElementById('untaglink_' + TrackID).style.display = 'none';
		
		document.getElementById('TblTrackId' + TrackID).style.display = 'none';	
		count = getCookie('tagged_count');
		if (count == 0)
		{
			document.getElementById('untagAllTrackId').style.display = 'none';	
			document.getElementById('noTaggedTrackId').style.display = 'inline';	
		}
	},'json','get');
	
}

function get_similar(TrackID)
{
	document.getElementById('loading_params' + TrackID).style.display = 'inline';
	jx.load('/get_similar_params.php?id='+TrackID,function(data) {
	
		document.getElementById('loading_params' + TrackID).style.display = 'none';
		
		var browsepopupdiv = document.getElementById("browsepopupdiv");
		if ((navigator.appName.indexOf("Microsoft") == -1) && (navigator.appName.toLowerCase().indexOf("opera") == -1)) {
			browsepopupdiv.style.visibility = '';
		} else {
			browsepopupdiv.style.display = 'block';
		}
		
		var optionswindow = document.getElementById("optionswindow");
	    optionswindow.find_similar(data);
	
	    dont_close_popup=true;
		if (closeTimeoutID!=-1) {
			clearTimeout(closeTimeoutID);
			closeTimeoutID=-1;
		}
	    setTimeout("dont_close_popup=false;",600);
	
	},'text','get');
	
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}







swsplayer = 0;

function popup_player(version_id, loop)
//popUpWindowCenter(URLStr, width, height)	
{
    width = 340;
    height = 250;
    width1 = width / 2;
    height1 = height / 2;
    x = screen.availWidth / 2 - width1;
    y = screen.availHeight / 2 - height1; 

    if(swsplayer && !swsplayer.closed)
    {
	   if (swsplayer.window.focus)
            swsplayer.window.focus();
	   // flash monituje sam czy się cos zmieniło co 0.5s wywołując funkcję get_newest_version_ID()
       // swsplayer.location = '/sws_player.php?v=' + version_id + '&l=' + loop;
       // AS2
	   //swsplayer.getFlash().SetVariable("/:reload_loop_var",loop);
	   //swsplayer.getFlash().SetVariable("/:act_version_ID",version_id);
	   //swsplayer.getFlash().SetVariable("/:replay_flag",1);
	   // AS3
	   //if (swsplayer.getFlash().reloadFunction) swsplayer.getFlash().reloadFunction(loop+"#"+version_id);
	   swsplayer.getFlash().reloadFunction(loop+"#"+version_id);
    }
    else
    {
    	swsplayer = open('/sws_player.php?v=' + version_id + '&l=' + loop, 'swsplayer', 'toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+x+', top='+y+',screenX='+x+',screenY='+y+'');
    }
    return false;
}

function _lit(obj) { obj.style.background='E8F0FA'; };
function _unlit(obj) { obj.style.background='F8F8F8'; };

function render_track(ID, name, description, composers, HD_flag, excl_flag, versions, my_tags, col, gens, tempo_feel, bpm) {
	var dat;
	
	dat='<table class="THD" cellpadding="0" cellspacing="0">';
	dat+='	<tr>';
	dat+='		<td class="TBL"></td>';
	dat+='		<td class="TBC">';
	dat+='		<div class="tN"><a href="/track/'+ID+'">'+name+'</a>';
	if (HD_flag) dat+='<a href="/24bit.html" id="_24b'+ID+'" onmouseover="show_hide_box(this, \'This track is 24bit enabled\', 32,-54);" onmouseout="show_hide_box(this,\'\',0,0);"><img src="/g/HD.png"></a>';
	if (excl_flag) dat+='<a href="/exclusive.html" id="_excl'+ID+'" onmouseover="show_hide_box(this, \'This track is Shockwave-Sound.com exclusive\', 32,-54);" onmouseout="show_hide_box(this,\'\',0,0);"><img src="/g/exclusive.png" style="margin-left:4px;"></a>';
	dat+='		</div>';
	dat+='		<div class="tCmp"><img src="/g/cmp.png">'+composers+'</div>';
	dat+='		</td>';
	dat+='		<td class="TBR"></td>';
	dat+='	</tr>';
	dat+='</table>';
	
	dat+='<div class="TCK">';
	dat+='<div class="TDESC">';
	dat+=description;
	if (tempo_feel) {
		var tf;
		switch(tempo_feel[0]) {
			case 1: tf="Very slow"; break;
			case 2: tf="Slow"; break;
			case 3: tf="Medium"; break;
			case 4: tf="Fast"; break;
			case 5: tf="Very fast"; break;
			default: tf="";
		}
		dat+=' <nobr>[Tempo feel: <b>'+tf+'</b>'
		if (bpm) {
			dat+=' <b> / '+bpm+' bpm</b>';
		}
		dat+=']</nobr>';
	}	
	
	dat+='</div>';
	if (navigator.appName.indexOf("Microsoft") != -1) {
		dat+='<div class="VRNS_IE">';
	} else {
		dat+='<div class="VRNS">';
	}
	dat+='<table class="THD" cellpadding="0" cellspacing="0">';
	
	var i,j,cart_img;
	//versions=[{name:'tom', price:19.95, id:123, cart:true},{name:'tom', price:19.95, id:123, all:true}];
	//versions=[];
	for(i=0; i<versions.length; i++) {
		dat+='<tr onmouseover="_lit(this)" onmouseout="_unlit(this)">';
		var verid;
		if (typeof versions[i].id!='number') {
			verid=versions[i].id[0];
		} else {
			verid=versions[i].id;
		}
		
		if (versions[i].loops>0) {
			dat+='	<td class="PLY" ></td>';
			dat+='	<td class="NAML">';
			dat+='	Set of '+versions[i].loops+' music loops [<a href="faq.html#musicloops">?</a>]&nbsp;';
			for(j=0; j<versions[i].loops; j++) {
				var lpnum=''+(j+1);
				if (lpnum.length<2) lpnum="0"+lpnum;
				dat+='	<a href="#" onclick="return popup_player('+versions[i].id+',\''+lpnum+'\')"><img onmouseout="this.src=\'/g/ply1.png\'" onmouseover="this.src=\'/g/ply2.png\'" src="/g/ply1.png"></a><div class="lnum">'+(j+1)+'</div>';
			}
			dat+='	</td>';
			dat+='	<td class="PRC">US$ '+versions[i].price+'</td>';
		} else {
			if (versions[i].noplay && (!versions[i].defplay)) {
				dat+='	<td class="PLY" ></td>';
			} else {
				if (versions[i].defplay) {
					dat+='	<td class="PLY" ><a href="/'+versions[i].plink+'"><img onmouseout="this.src=\'/g/ply1.png\'" onmouseover="this.src=\'/g/ply2.png\'" src="/g/ply1.png"></a></td>';
				} else {
					dat+='	<td class="PLY" ><a href="#" onclick="return popup_player('+verid+',\'\')"><img onmouseout="this.src=\'/g/ply1.png\'" onmouseover="this.src=\'/g/ply2.png\'" src="/g/ply1.png"></a></td>';
				}
			}
			if (versions[i].name.toLowerCase().indexOf("underscore")>=0) {
				versions[i].name+=' [<a href="/underscore.html">?</a>]';
			} else if (versions[i].name.toLowerCase().indexOf("stinger")>=0) {
				versions[i].name+=' [<a href="/stinger.html">?</a>]';
			}
			dat+='	<td class="NAM">'+versions[i].name+'</td>';
			dat+='	<td class="PRC">US$ '+versions[i].price+'</td>';
		}
		
		if (versions[i].cart) {
			dat+='	<td class="SHP"><a href="/xt_cart_remove_new.php?vid='+versions[i].id+'&linkback='+escape(getRelHREF())+'" id="hshp'+verid+'" onmouseover="show_hide_box(this, \'Remove from shopping cart\', 17,-51);" onmouseout="show_hide_box(this,\'\',0,0);"><img onmouseout="this.src=\'/g/ucrt1.png\'" onmouseover="this.src=\'/g/ucrt2.png\'" src="/g/ucrt1.png"></a></td>';
		} else {
			dat+='	<td class="SHP"><a href="/xt_cart_add_new.php?vid='+versions[i].id+'&linkback='+escape(getRelHREF())+'" id="hshp'+verid+'" onmouseover="show_hide_box(this, \'Add to shopping cart\', 17,-51);" onmouseout="show_hide_box(this,\'\',0,0);"><img onmouseout="this.src=\'/g/crt1.png\'" onmouseover="this.src=\'/g/crt2.png\'" src="/g/crt1.png"></a></td>';
		}
		
		if ((versions[i].plink=='') || versions[i].defplay) {
			dat+='	<td class="DL"></td>';
		} else {
			dat+='	<td class="DL"><a href="'+versions[i].plink+'" id="hdl'+verid+'" onmouseover="show_hide_box(this, \'Download MP3 preview file\', 17,-51);" onmouseout="show_hide_box(this,\'\',0,0);"><img onmouseout="this.src=\'/g/dl1.png\'" onmouseover="this.src=\'/g/dl2.png\'" src="/g/dl1.png"></a></td>';
		}
		
		dat+='</tr>';
	}
	dat+='</table>';
	dat+='</div>';
	
	dat+='<div class="FTR">';

	var tag_link,clk;
	if (getCookie("tagged_"+ID)==ID) {
		tag_link = "<a id=\"taglink_"+ID+"\" href=\"#\" id='tag"+ID+"' onmouseover=\"show_hide_box(this, 'Add this track to <b>My tags</b> (lightbox)', 35,-45);\" onmouseout=\"show_hide_box(this,'',0,0);\" onclick=\"tag_track("+ID+"); return false\" style=\"display:none\">Tag this track</a>";
		clk = (my_tags) ? "untag_track_hide("+ID+"); return false;" : "untag_track("+ID+"); return false;";

		tag_link += "<a id=\"untaglink_"+ID+"\" href=\"#\" id='untag"+ID+"' onmouseover=\"show_hide_box(this, 'Remove this track from <b>My tags</b> (lightbox)', 40,-45);\" onmouseout=\"show_hide_box(this,'',0,0);\" onclick=\""+clk+"\">Untag this track</a>";
		dat+='<div class="FTAG"><img id="tagimg'+ID+'" src="/g/iuntag.png"> ['+tag_link+'<img src="/g/loading_TAG.gif" alt="" id="loading_'+ID+'" style="display:none"/>]</div>';
	} else {
		tag_link = "<a id=\"taglink_"+ID+"\" href=\"#\" id='tag"+ID+"' onmouseover=\"show_hide_box(this, 'Add this track to <b>My tags</b> (lightbox)', 35,-45);\" onmouseout=\"show_hide_box(this,'',0,0);\" onclick=\"tag_track("+ID+"); return false\">Tag this track</a>";
		tag_link += "<a id=\"untaglink_"+ID+"\" href=\"#\" id='untag"+ID+"' onmouseover=\"show_hide_box(this, 'Remove this track from <b>My tags</b> (lightbox)', 40,-45);\" onmouseout=\"show_hide_box(this,'',0,0);\" onclick=\"untag_track("+ID+"); return false\" style=\"display:none\">Untag this track</a>";

		dat+='<div class="FTAG"><img id="tagimg'+ID+'" src="/g/itag.png"> ['+tag_link+'<img src="/g/loading_TAG.gif" alt="" id="loading_'+ID+'" style="display:none"/>]</div>';
	}
	
	if (col) {
		dat+='<div class="FCOL"><img src="/g/icol.png"> [<a href="/product/'+col.id+'" id="col'+ID+'" onmouseover="show_hide_box(this, \'View CD collection containing the track\', 35,-45);" onmouseout="show_hide_box(this,\'\',0,0);">'+col.name+'</a>]</div>';
	}
	if (gens) {
		dat+='<div class="FGEN"><img src="/g/igen.png">'+gens+'</div>';
	}
	if (tempo_feel) {
		dat+='<div class="FSIM"><img src="/g/isim.png"> [<a href="#" id="sim'+ID+'" onmouseover="show_hide_box(this, \'Launch <b><i>Advanced Browse</i></b> fitting<br/>the track parameters\', 30,-57);" onmouseout="show_hide_box(this,\'\',0,0);" onclick="get_similar('+ID+'); return false;">Find Similar</a><img src="/g/loading_TAG.gif" alt="" id="loading_params'+ID+'" style="display:none"/>]</div>';
	}
	dat+='</div>';

	dat+='</div>';
	document.getElementById("track"+ID).innerHTML=dat;
}

function getRelHREF() {
	return location.href.substring(location.href.indexOf('/', 14));
}


//////////////////////////////////////////////////////////
//
// hints
//
//////////////////////////////////////////////////////////

// Moves the box object to be directly beneath an object.  
function move_box(an, box, offx, offy)  
{  
    var cleft = 0;  
    var ctop = 0;  
    var obj = an;  
  
    while (obj.offsetParent)  
    {  
        cleft += obj.offsetLeft;  
        ctop += obj.offsetTop;  
        obj = obj.offsetParent;  
    }  
    cleft+=offx;
    ctop+=offy;

    box.style.left = cleft + 'px';  
  
    ctop += an.offsetHeight + 8;  
  
    if (document.body.currentStyle &&  
        document.body.currentStyle['marginTop'])  
    {  
        ctop += parseInt(  
            document.body.currentStyle['marginTop']);  
    }  
  
    box.style.top = ctop + 'px';  
    box.style.position = 'absolute'; 
}  

function show_hide_box(an, html, offx, offy)  
{  
    var myid = an.id+"hint";
    var boxdiv = document.getElementById(myid);
    
    if (!offx) offx=0;
    if (!offy) offy=0;
    
    if (boxdiv != null)  
    {  
        if (boxdiv.style.display=='none')  
        {  
            move_box(an, boxdiv, offx, offy);
            boxdiv.style.display='block';  
  
            bringToFront(boxdiv);  
        }  
        else
        {
            boxdiv.style.display='none';  
        }
        return false;  
    }
    
    boxdiv = document.createElement('div');  
    boxdiv.setAttribute('id', myid);
    boxdiv.className='HINT';
  
    document.body.appendChild(boxdiv);
    bringToFront(boxdiv);  
  
    var offset = 0;  
  
    boxdiv.innerHTML=html;
    move_box(an, boxdiv, offx, offy);  
  
    return false;  
}  
  
function getAbsoluteDivs()  
{  
    var arr = new Array();  
    var all_divs = document.body.getElementsByTagName("DIV");  
    var j = 0;  
  
    for (i = 0; i < all_divs.length; i++)  
        if (all_divs.item(i).style.position=='absolute')  
        {  
            arr[j] = all_divs.item(i);  
            j++;  
        }  
  
    return arr;  
}  
  
function bringToFront(obj)  
{  
    if (!document.getElementsByTagName)  
        return;  
  
    var divs = getAbsoluteDivs();
    var max_index = 0;
    var cur_index;
  
    for (i = 0; i < divs.length; i++)  
    {  
        var item = divs[i];  
        if (item == obj ||
            item.style.zIndex == '')
            continue;  
  
        cur_index = parseInt(item.style.zIndex);
        if (max_index < cur_index)
        {
            max_index = cur_index;
        }
    }

    obj.style.zIndex = max_index + 1;
}

//-->

