var drop_box_timeout = 6000; // czas po jakim zmieniaj si newsy
// mediaButtonsHtml = new Array();

function show_mail(user,domena,kraj,attr) {
	var start = "<a href=\"mailto:"+user+"@"+domena+"."+kraj+"\" title=\"\""
	+ attr + ">";
	var end = "</a>";
	document.write(start+user+"@"+domena+"."+kraj+end);
	return 0;
}


function verify(form) {
var Wzor=/^[0-9a-zA-Z._-]+\@[0-9a-zA-Z_-]+\.[0-9a-zA-Z.]+$/;

	if (form.name.value.length < 3) {
		alert("Please enter your name.");
		form.name.focus();
		return false;
    }
	if(Wzor.test(form.email.value)==false) {
		alert("Please enter correct email address.");
		form.email.focus();
		return false;
    }	
	if (form.msg.value.length < 6) {
		alert("Please enter message.");
		form.msg.focus();
		return false;
    }	

return true;		
}

var active_news_box = 1;
function MoveNewsBox() {
	box_obj = $('news_'+active_news_box);
	active_news_box++;
	if($('news_'+active_news_box)) { // szukanie nastpnego boxa do podmiany
		next_box_obj = ($('news_'+active_news_box));
	} else {
		active_news_box = 1;
		next_box_obj = ($('news_'+active_news_box));
	}
	
	if(box_obj !== next_box_obj) { // gdy jest wicej ni 1 obiekt do zmiany
			
			new Effect.Parallel(
			[
				new Effect.Move (box_obj, { x: -250, y: 0, mode: 'absolute'}),
				new Effect.Move (next_box_obj, { x: 0, y: 0, mode: 'absolute'})
			], {
				duration: 1,
				beforeStart: function() { next_box_obj.style.left = '250px'; },
				afterFinish: function() { box_obj.style.left = '250px'; }
			});
	
			setTimeout("MoveNewsBox();",drop_box_timeout);
	}
}


function DropNewsBox() {
	box_obj = $('news_'+active_news_box);
	active_news_box++;
	if($('news_'+active_news_box)) { // szukanie nastpnego boxa do podmiany
		next_box_obj = ($('news_'+active_news_box));
	} else {
		active_news_box = 1;
		next_box_obj = ($('news_'+active_news_box));
	}
	
	if(box_obj !== next_box_obj) { // gdy jest wicej ni 1 obiekt do zmiany
	
			new Effect.Parallel(
			[
				new Effect.Move (box_obj, { x: -250, y: 0, mode: 'absolute'})
			], {
				duration: 0.6,
				beforeStart: function() { next_box_obj.style.left = '0px'; next_box_obj.style.display = 'none'; },
				afterFinish: function() { new Effect.Appear(next_box_obj, { duration: 0.5 }); }
			});
			
			setTimeout("DropNewsBox();",drop_box_timeout);
	}
}


var open_bio = null;

function activate_directors() {
	var divs = $$('#all_team_obj .team_obj h1');
	for(var i=0; i<divs.length; i++) { // przekazuje wskaznik do elementu div.bio
		divs[i].onclick = function() { 
			var tmp = this.nextSibling.nextSibling;
			if(tmp.tagName != "DIV") tmp = this.nextSibling.nextSibling.nextSibling.nextSibling; // IE i FF inaczej interpretuja nextSibling ;-|
			if(!open_bio) {
							tmp.style.display = 'block';
							open_bio = tmp;
						} else if(open_bio == tmp) {
							open_bio.style.display = 'none';
							open_bio = null;
						} else {
							open_bio.style.display = 'none';
							tmp.style.display = 'block';
							open_bio = tmp;
						}
		}
	}
}

function replace_captions() {


	var caps = $$('h1.caption');
	var counter = 0;
	for(var i=0; i < caps.length; i++) {
		if(caps[i].innerHTML.indexOf('write.php?write')>0)
			{
					var img = caps[i].getElementsByTagName("img")[0];
					var tag = img.alt;
					if(img.parentNode.tagName != "A") caps[i].removeChild(img);
					else caps[i].removeChild(img.parentNode);
					
					var div = document.createElement("div");
					div.setAttribute("id", "my_sirf_"+counter);
					div.setAttribute("class", "my_sirf");
					caps[i].appendChild(div);
					
					var so = new SWFObject("flash/my_sifr.swf", "my_sirf_obj_"+counter, "100%", "100%", "8", "");
					so.addVariable("rozmiar", "14");
					so.addVariable("kolor", "0x858585");
					so.addVariable("tekst", tag.replace(/&/gi, "AND"));
					so.addVariable("obj", "my_sirf_"+counter);
					so.addVariable("szer", "460");
					so.addParam("salign", "lt");
					so.addParam("scale", "noscale");
					so.addParam("wmode", "transparent");
					so.write("my_sirf_"+counter);	
					counter++;
			}
	}
}

function ustawFlash(vars) {
	var tmp = vars.toString().split(",");
	$(tmp[0]).style.width = tmp[1]+'px';
	$(tmp[0]).style.height = tmp[2]+'px';
	//alert(tmp[0]+' '+tmp[1]+' '+tmp[2]);
}

window.onload = function() {

	if($('news_'+active_news_box)) {
		if(window.location.href.substr(window.location.href.length-1,1) == "/" || window.location.href.indexOf("index") > 0) {
			setTimeout("MoveNewsBox();",drop_box_timeout);
		} else {
			setTimeout("DropNewsBox();",drop_box_timeout);
		}
		
	}

	if($('all_team_obj')) {
		activate_directors();	
	}
	
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if(version["major"] >= 8) {
		replace_captions(); // zamienianie naglowkow na flashe...
	}
	
}


/* OBSLUGA LIGBOX-VIDEO */
function showVideo() {
	resetMediaButtons();
    $('lightboxImage').hide();
    

    var so = new SWFObject("flash/player8.swf","PlayerNew","404","348","7","#000000");
    so.addParam("allowScriptAccess","always");
    so.addParam("scale","noscale");
    so.addParam("wmode","transparent");
    so.write('VideoContainer');
    
    $('VideoContainer').show();
    
}

function showVideo2() {
	resetMediaButtons();
    $('lightboxImage').hide();
    

    var so = new SWFObject("flash/playerWideScreen.swf","PlayerNew","535","348","7","#000000");
    so.addParam("allowScriptAccess","always");
    so.addParam("scale","noscale");
    so.addParam("wmode","transparent");
    so.write('VideoContainer');
    
    $('VideoContainer').show();
    
}
	sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:"scripts/sifr2/tahoma.swf", sColor:"#454545", sLinkColor:"#454545", sBgColor:"#FFFFFF", sHoverColor:"#454545", nPaddingTop:0, nPaddingBottom:0, sWmode:"transparent", sFlashVars:"textalign=justify&offsetTop=0"}));
	sIFR.replaceElement(named({sSelector:"h5", sFlashSrc:"scripts/sifr2/tahoma-bold.swf", sColor:"#828282", sLinkColor:"#828282", sBgColor:"#FFFFFF", sHoverColor:"#828282", nPaddingTop:0, nPaddingBottom:0, sWmode:"transparent", sFlashVars:"textalign=left&offsetTop=0"}));
	
	/* SIFR 3 
	var tahoma = { src: 'tahoma.swf'};

	sIFR.delayCSS  = true;
	sIFR.activate(tahoma);
	sIFR.replace(tahoma, {
	  selector: 'h4',
	  wmode: 'transparent'
	  ,css: [
	    '.sIFR-root { color:#454545; margin:0px; text-align:justify;  }'
	  ]
	});
	sIFR.replace(tahoma, {
	  selector: 'h5',
	  wmode: 'transparent'
	  ,css: [
	    '.sIFR-root { color:#828282; margin:0px; font-weight:bold;  }'
	  ]
	});
	/* </> SIFR 3 */
	
function playaudio(pathtofile,div_id) {
	resetMediaButtons();
	
	$(div_id).innerHTML = "";

    var so = new SWFObject("flash/sound.swf?path=" + pathtofile,"PlayerNew","100","13","7","#333333");
    so.addParam("allowScriptAccess","always");
    // so.addParam("scale","noscale");
	so.addParam("wmode","transparent");
    so.write(div_id);
    
}

function playvideo($pathtofile) {
	resetMediaButtons();
	
    $('lightboxImage').hide();

    var so = new SWFObject("../flash/player8.swf?path=" + $pathtofile,"PlayerNew","404","348","7","#000000");
    so.addParam("allowScriptAccess","always");
    so.addParam("scale","noscale");
    //so.addParam("wmode","transparent");
    so.write('VideoContainer');
    
    $('VideoContainer').show();
    
}

function resetMediaButtons()
{
	if(!window.mediaButtonsHtml) {
		window.mediaButtonsHtml = $$('div.media_icons ');
		media_icons = Array();
		for(var i=0 ; i<window.mediaButtonsHtml.length ; i++) {
			media_icons[i] = window.mediaButtonsHtml[i].innerHTML;
		}
	}
	
	for (var i=0 ; i<window.mediaButtonsHtml.length ; i++) {
		$(window.mediaButtonsHtml[i]).innerHTML = media_icons[i];
	}
	
	myLightbox.initializeAnchors();
}
