﻿//JavaScript

//Çalan parça bilgileri... Mart 2008
function Play_Info()
{	
	var wmpDynamic = document.getElementById("wmpDynamic")
	if (!wmpDynamic){ 
		return;
	}

    var Media = wmpDynamic.currentMedia;
    if(!Media)
    {
        return;
    }

    // Retrieve the metadata we want to display.
    var Title = Media.getItemInfo("Title");
    var Artist = Media.getItemInfo("WM/AlbumArtist");
    var AlbumTitle = Media.getItemInfo("WM/AlbumTitle");
    var Duration = Media.durationString;
    // Streaming media always returns zero.
 //   if(Duration == "00:00"){...}    

    var strHTML = "Şarkı/Title: " + Title ;
    strHTML += "\nSanatçı/Artist: " + Artist ;
    strHTML += "\nAlbüm/Album: " + AlbumTitle ;
	strHTML += "\nAçıklama/Description: " + Media.getItemInfo("Description") ;
    strHTML += "\nSüre/Duration: " + Duration ;
	strHTML += "\nParça No/Track: " + Media.getItemInfo("WM/Track");
    strHTML += "\nYıl/Year: " + Media.getItemInfo("WM/Year");
    strHTML += "\nTür/Genre: " + Media.getItemInfo("Genre");
	strHTML += "\nYazar/Author: " + Media.getItemInfo("Author");
	strHTML += "\nBestekar/Composer: " + Media.getItemInfo("Composer");
	strHTML += "\nBit Değeri/Bitrate: " + Math.round(Media.getItemInfo("Bitrate")/1000) + " Kbps" ;
	strHTML += "\nBoyut/File Size: " + Math.round(Media.getItemInfo("FileSize")/1024) + " KB";
	strHTML += "\nTelif Hakkı/Copyright: " + Media.getItemInfo("Copyright") ;
	strHTML += "\n\n          www.mbirgin.com          ";
	
//	alert(strHTML);
	return strHTML;
}


/*Otomatik olarak sonraki onclick="Play(URL)" linkini bulup, URL 'yi oynatır.*/
var OrderPlaying = 0;
function Play_Next() {
    var lnk_All = document.getElementsByTagName("a");
   
    var lnk_Count = lnk_All.length;
    var lnkPlay;
    var gAttr = "";

    while(OrderPlaying<=lnk_Count){      //Dosya sonuna kadar, "a" için taranmamışsa
        OrderPlaying+=1;	
//	        alert (lnk_Count + " / " + OrderPlaying);

        lnkPlay = lnk_All[OrderPlaying]; // () değil [] olmalıymış! :)
     	if (lnkPlay) {
     	    try {
     	        gAttr = lnkPlay.getAttribute("onclick").toString();
   	            var gStart = gAttr.indexOf("Play(");
     	        if (gStart >= 0) {
     	            var gEnd = gAttr.lastIndexOf(")")
     	            var gURL = gAttr.substring(gStart + 6, gEnd - 1);
      	            Play(gURL);                            //			        lnkPlay.click();
     	            return;
     	            break;
     	        }
     	    } catch (ex) {
     	    gAttr = "";
     	}
     	}
    }
}
         	                            	        

/* Description : Sayfada "divWMP" isimli bir DIV olmalıdır. */
	function Play(pURL){
		var objSender;
	
		try{
			objSender=event.srcElement;
		}catch(err){

		}
		
		var vol=60;		
    	var wmpDynamic = document.getElementById("wmpDynamic");
    	if (wmpDynamic){ 
    		try{
    			vol=wmpDynamic.settings.volume;
    			wmpDynamic.controls.stop();				
			}catch(ex){
			
			}
		}
	
		var strWMP="";
		if (objSender!=null){
			var	strTitle=objSender.innerText;
			strWMP = "<span id='spnTitle'><b>" + strTitle + "</b></span><br>";
		}
		
		
		var strWMP_More="";
		var strExt=pURL.substring(pURL.length-4, pURL.length).toLowerCase();		
		var strServer=pURL.substring(0,7).toLowerCase();		
		if ((strServer=="http://") && (strExt==".mp3" || strExt==".wma" || strExt==".wmv")){
			strWMP_More += "<br><span id='spnDownload'><a onclick='alert(title)' title='Sağ tıklayıp, hedefi farklı kaydediniz.\n Right click and save target as...' target='_blank' rel='nofollow' href=\"" + pURL + "\">İndir/Download</a></span>";
		}else{
			strWMP_More += "<br><span id='spnDownload'>...</span>";
		}
		strWMP_More += " | <span id='spnInfo'><a onclick='alert(Play_Info())' href='#divWMP'>Bilgi/Info</a></span>";
	
		strWMP_More += " | <span id='spnEmbed'><a target='wndEmbed' href='#' onclick='Popup(&quot;./Core/Embed/EmbedWMP.aspx?Mode=ShowEmbedCode&URL=" + pURL + "&quot;); return false;'>Sitene Ekle/Embed</a></span>";

        var Boy=60;
        var En=320;
        if (strExt==".wmv"){
            Boy=320;
        }
		
		strWMP += "<OBJECT id='wmpDynamic' type='application/x-oleobject' height='" + Boy + "' width='" + En + "' classid='clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6'>";
		strWMP += '<PARAM NAME="URL" VALUE="' + pURL + '">';
		strWMP += "<PARAM NAME='autoStart' VALUE='-1'>";
		// strWMP += "<PARAM NAME='uiMode' VALUE='mini'>"; //Pozisyon göstergesi görünmüyor!!! 
		strWMP += "<PARAM NAME='volume' VALUE='" + vol + "'>";
		strWMP += "<embed id='wmpDynamic' autostart='-1' src='"+ pURL + "' height='" + Boy + "' width='" + En + "' border='0' type='application/x-mplayer2'/></embed>";
		strWMP += "</OBJECT>";
	
		strWMP += strWMP_More;
	
	//Alt kısım Aralık 2008 'de eklendi. "divWMP" elemanına bakılacak. Bulunamazsa, "divWMP_Common" elemanına bakılacak.
	    var divTarget = document.getElementById("divWMP");
    	if (!divTarget){ 
		    divTarget=document.getElementById("divWMP_Common");
		}
        divTarget.innerHTML=strWMP;
	
	}


	/* Description : Locate Popup page to center. */
	function Popup(pURL, pH, pW) {
	    //if (typeof pH == "undefined") pH = "default value";
	    if (!pW) {
	        pW = 320;
	    }
	    if (!pH) {
	        pH = 250;
	    }

	    //window.status = '';
	    var winleft = (screen.width - pW) / 2;
	    var wintop = (screen.height - pH) / 2;

	    var args = "top=" + wintop + ", left=" + winleft + ", width=" + pW + ", height=" + pH + ", toolbar=0, menubar=0, scrollbars=-1, status=-1, resizable=-1";

	    var wForm = window.open(pURL, "wndPopup", args);
	    wForm.focus();

	    return wForm;
	}


	/* Description : Locate Popup page to center. */
	function PopIn(pURL, pH, pW) {
	    //if (typeof pH == "undefined") pH = "default value";
	    if (!pW) {
	        pW = "100%";
	    }
	    if (!pH) {
	        pH = "250px";
	    }

	    var div = document.getElementById("divPopIn");
	    var strHTML = "<center><a href='#' onclick='RemovePopIn();'><b>Kapat</b></a></center>";
	    strHTML += "<center><iframe src='" + pURL + "' style='width:" + pW + "; height:" + pH + ";' frameborder='0'></iframe></center>";	    
	    if (!div) {
	        alert("divPopIn elemanı bulunamadı!");
	    } else {
	    div.innerHTML = strHTML;
	    div.style.height = pH;	   
	    }
	    
	}

	function RemovePopIn() {
	    var div = document.getElementById("divPopIn");
	    var strHTML = "";
	    if (!div) {
	     //   alert("divPopIn elemanı bulunamadı!")
	    } else {
	    //alert(div.style.height);
	        div.style.height = "1px";
	        div.innerHTML = strHTML;
	    }
	}



/* Description : İlgili elemanın görünüp, gizlenmesini sağlar. */
function ToggleDisplay(pID) {

    var obj=document.getElementById(pID);
    
    if (obj==null) return;
    
    if (obj.style.display==''){
        obj.style.display='none';
    }else{
        obj.style.display=''; 
    }
}


/*İlgili nesnenin işlem yaptığını gösteren bir simge ekler */
function InProgress(pIDSource) {
    var objSource = document.getElementById(pIDSource);
    if (objSource != null) {
        objSource.className = "cssInProgress";
        objSource.disabled = true;
    }
}



function CheckEnterKey(e, btnId) {
    var evt = e ? e : window.event;
    var btn = document.getElementById(btnId);
    if (btn) {
        if (evt.keyCode == 13) {
            btn.click();
            return false;
        }
    }
}



/*Büyük resimleri otomatik olarak küçültür */
function Resize_All_Big_Images() {
    var MaxWidth = 550;

    var Container = document.getElementById("MainContentCell");
    if (Container == null) { return; }
    
    var All_Images = Container.getElementsByTagName("img");
    //All_Images = document.images;
    
    for (var i = 0; i < All_Images.length; i++) {
        var TheImg = All_Images[i];  //document.images[x];

        var iHeight = TheImg.height;
        var iWidth = TheImg.width;

        if (iWidth > MaxWidth) {
            var Ratio = MaxWidth / iWidth;
            var NewHeight = Ratio * iHeight;
            var NewWidth = MaxWidth;
            TheImg.height = NewHeight;
            TheImg.width = NewWidth;
            //alert(Ratio);

            TheImg.style.cursor = 'crosshair';
            TheImg.onclick = function() {
                var picture = window.open(this.src);
                picture.focus();
                return false;
            }
        }
    }
}

window.onload = function() {Resize_All_Big_Images();}

