﻿var ie=document.all ? true : false;
var ie5=(document.all && !document.getElementById)? (true):(false);if (ie5){document.getElementById=function (e){return document.all[e];}}
var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie 6.")>-1 ;
var isIE7 = navigator.userAgent.toLowerCase().indexOf("msie 7.")>-1 ;
var isIE8 = navigator.userAgent.toLowerCase().indexOf("msie 8.")>-1 ;
var isGecko = navigator.userAgent.toLowerCase().indexOf("gecko")>-1 ;
var isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox")>-1 ;




function trace(s){
	$("debugText").innerHTML = "|" + s + "|" + "<br/>" + $("debugText").innerHTML;
}

function padzero(n){
	if (n<10)n="0"+n;
	return n;
}

var onDomReady = function(f){
	window.addEvent('domready',f);
}

String.implement("forceInt",function(){
	var n = this.toInt();
	return isNaN(n) ? 0 : n;
	});

Element.implement("show",function(){this.style.display='';});
Element.implement("hide",function(){this.style.display='none';});
Element.implement("toggle",function(){
	this.style.display =  this.style.display == 'none' ? '' : 'none';
	});

function AjaxErrorHandler(oError){
	alert ("An error occured in your ajax call. \n\nError message:\n" + oError._message);
	AlertToPopup(oError);
}

function AlertToPopup(o){
	var w = window.open('',null,'');
	w.document.open();
	w.document.write ("<style>* {font-family: courier; } li {margin-bottom: 20px; }</style>");
	w.document.write ("<ul>");
	w.document.write(GetObjectPropertiesList(o));
	w.document.write ("</ul>");
	w.document.close();
	w.focus();
}

function GetObjectPropertiesList(o){
	var arr = [];
	for (var i in o){
		arr.push("<li>"+i + ":" );
		try{
			arr.push(o[i]);
		}catch(ex){
			arr.push("error:" + ex.description);
		}
		arr.push("</li>");
	}

	return arr.join("");
}


 // there is only one lightbox at a time so we can save its ID in a global variable
var lastLightboxOpened = null;

function ShowLightbox(oOptions  ){
	var lightboxId = "LightboxWrapper";
	var o = $(lightboxId);
	if (!o)return;

	// make the overlay div the last and display it
	$("LightboxOverlay").show();
	$("LightboxOverlay").set("opacity", 0.5);
	var bg = $("LightboxOverlay");
	var size = window.getScrollSize();
	bg.style.height = size.y + "px";

	if (oOptions && oOptions.htmlContent){
		$("LightboxContent").innerHTML = oOptions.htmlContent;
	}
	if (oOptions && oOptions.OKLinkTitle){
		$("LightboxOK").innerHTML = oOptions.OKLinkTitle;
	}else{
		$("LightboxOK").innerHTML = "Save";
	}


	$(lightboxId).show();
	o.style.left = (window.getScrollSize().x - o.getScrollSize().x)/2 + "px";
	o.style.top = (window.getScroll().y + 100) + "px";

	lastLightboxOpened = lightboxId;

	$("LightboxOK").removeEvents("click");
	$("LightboxOK").addEvent("click", function(e){
		e = new Event(e);
		e.stop();

		if(oOptions && oOptions.onOKClick!=null)oOptions.onOKClick();
		CloseLightbox();
	});

}

// since there is only one lightbox at a time we dont need to pass the ID as argument
function CloseLightbox(){
	$("LightboxOverlay").hide();
	$("LightboxWrapper").hide();
	lastLightboxOpened = null;
}

function LightboxSave(){

	CloseLightbox();
}


function hovermenu(e,isOver){
	if (isOver){
		$(e).getParent().addClass("over");
	}else{
		$(e).getParent().removeClass("over");
	}
}





function playVideo(url,w,h){
	//var video = window.open("video.asp?url="+url,null,'scalable=yes,resizeable=yes,status=yes,scrollbars=no,width='+w+',height='+h+',top=10,left=10');
	//video.focus();
	//$("VideoFrame").src = "http://www.w3.center-site-net.com/bigben/modules/videos/mediaplayer.asp?url="+encodeURIComponent(url);
}

function setMaxWidth(img,maxWidth){
	if (!img.width)return;
	if (img.width>maxWidth)img.width=maxWidth;
}

function SetSongPlayer(oLink){

	var url = oLink.href;

	oLink.addEvent("click", function(e){
		e = new Event(e)
		e.stop();

		var playerHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="165" height="38" >'+
					  '<param name=movie value="niftyplayer.swf?file='+encodeURIComponent(url)+'&as=1">'+
					  '<param name=wmode value=opaque>'+
					  '<param name=quality value=high>'+
					  '<param name=bgcolor value=#FFFFFF>'+
					  '<embed src="niftyplayer.swf?file='+encodeURIComponent(url)+'&as=1" quality=high bgcolor=#FFFFFF wmode=opaque width="165" height="38" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">'+
					  '</embed></object>';

		var clickPos = oLink.getCoordinates();

		var x = clickPos.left;
		var y = clickPos.top;

		$("mp3player_single_wrap").setStyles({
			display: "block",
			left: (x - 205) ,
			top: ( y - 12)
			});
		$("mp3player_single").set("html" , playerHtml);


		if (Browser.Engine.trident && Browser.Engine.version<8 ){

			var pagePos = $("page").getCoordinates();
			var of = getOffsetLeft($("page"));

			x = of + of/2 ;

			$("mp3player_single_wrap").setStyles({
				left: x
			});
		}


	});

}

function closePlayer(){
	$("mp3player_single_wrap").setStyles({
			display: "none"
			});
		$("mp3player_single").set("html" , "");
}

function SetMinimalPageHeight(){
	if ($("page")){
		var size = $("page").getSize();
		if (size.y<500){
			$("page").setStyle("height", "500px");
		}
	}
}

function AutoFill(){
	ar = document.getElementsByTagName("input");
	for(var i in ar){
		if (ar[i].type=="text"){
			ar[i].value=ar[i].name;
			if (ar[i].name=="email")ar[i].value="test@test.com";
		}

	}
}
function resizeByIframe(){

	if (!$("contentIframe"))return;
	var h = parseInt($("contentIframe").style.height.replace("px",""));
	if (h==370)return;
	$("ContentFrameWrap").style.height = ( h + 20) + "px";
	$("Frame").style.height = ( h-2) + "px";


}


function AddClasses(){
	var s = "";
	if ( ie ){
		s += " ie ";

		if (isIE6){
			s += " ie6 ";
		}else if (isIE7){
			s += " ie7 ";
		}else if (isIE8){
			s += " ie8 ";
		}

	}else{

		if (isGecko){
			s += " gecko ";
		}
		if (isFirefox){
			s += " firefox ";
		}
	}

	if (s!=""){
		document.body.className += s;
	}


}


function setHTML(id,str)	{var o=$(id);if(!o)return;o.innerHTML=str;}
function getHTML(id)		{var str="";var o=$(id);if (o)str=o.innerHTML;return str;}
function setFocus(id)		{var o=$(id);if(!o)return;o.focus();}
function setValue(id,str)	{var o=$(id);if(!o)return;o.value=str;}
function autoselect(id,str)	{var o=$(id);if(!o)return;if (!o.length)return;for (var i=0;i<o.length; i++){if (o[i].value==str){o.selectedIndex=i;break;}}}

function removeClass(o, str){replaceClass(o,str,"");}
//function addClass(o,str){if (!o)return;o.className = o.className + " " + str;}

function getOffsetTop (el){var ot = el.offsetTop;while ( ( el = el.offsetParent ) != null ){	ot += el.offsetTop;	}return ot;}
function getOffsetLeft (el){var ot = el.offsetLeft;while ( ( el = el.offsetParent ) != null ){ot += el.offsetLeft;}return ot;}


onDomReady(function(){

	AddClasses();

	if (typeof(MenuMatic)!="undefined"){
		var myMenu = new MenuMatic();
	}

	//SetMinimalPageHeight();

	if (typeof(siteId)!="undefined"){
		var ar = $$("a");
		var a;
		for(var i in ar){
			a = ar[i];
			if(typeof(a)=="function")continue;

			if (a.hasClass && a.hasClass("newWindow")){
				a.addEvent("click", function(e){
					//e = new Event(e);
					//e.stop();
					//window.open(a.href);
					//a.set("target" , "_blank");
				});
			}

			if (a.href && a.href.indexOf("javascript:")==-1 && a.href.indexOf("mailto:")==-1 ){
				
				if (a.href.indexOf(".mp3")>-1){
					SetSongPlayer(a);
				}else if (a.href.toLowerCase().indexOf("s=")==-1 && a.href.toLowerCase().indexOf("http://")==-1){
					
					a.href = a.href + (a.href.indexOf("?")>-1 ? "&" : "?" ) + "s=" + siteId ;
				}
			}
		}
	}




	if (location.search.indexOf("debug")>-1){
		AutoFill();
	}

});

var newwin;
function showAlbumSongs(albumId){
	newwin = window.open("moreinfo.asp?type=songs&id="+albumId,'songs'+albumId,'width=350,height=672,resizeable=yes,status=yes,scalable=yes,scrollbars=no');
	newwin.focus();
}
function showAlbumInfo(albumId){
	newwin = window.open("moreinfo.asp?type=album&id="+albumId,'album'+albumId,'width=350,height=672,resizeable=yes,status=yes,scalable=yes,scrollbars=no');
	newwin.focus();
}

function ShowSongInfo(singleId){
	newwin = window.open("moreinfo.asp?type=single&id="+singleId,'single'+singleId,'width=350,height=672,resizeable=yes,status=yes,scalable=yes,scrollbars=no');
	newwin.focus();
}

function ShowCooperationInfo(songId){
	newwin = window.open("moreinfo.asp?type=cooperations&id="+songId,'cooperation'+songId,'width=350,height=672,resizeable=yes,status=yes,scalable=yes,scrollbars=no');
	newwin.focus();
}


function ShowCopyrights(){
	newwin = window.open('moreinfo.asp?type=copyrights','copyrights','width=350,height=672,resizeable=yes,status=yes,scalable=yes,scrollbars=no');
	newwin.focus();
}



function EnlargeImage(url){

	if (url.indexOf("http")==-1 && url.indexOf(filesPrefix)==-1){
		url = filesPrefix  + url;
	}

	var html = '<img src="'+ url+'" alt="טוען תמונה..." onload="this.alt=\'\'" />'

	$("Picture").set("html", html);
}

function EnlargeVideo(url){

	var videoId = url.substring( url.indexOf("v=")+2);
	if (videoId.indexOf("&")>-1)
	{
		videoId = videoId.substring( 0, videoId.indexOf("&"));
	}

	var html = '<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/VIDEOID&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/VIDEOID&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>'
	html = html.replace(/VIDEOID/g , videoId);

	$("Picture").set("html", html);

}

