/*<?php
	require_once("../settings.php");
	header('Content-type: text/javascript');
	printf("BASE_URL = \"%s\";\n", BASE_URL);
	printf("CODE_DIR = \"%s\";\n", CODE_DIR);
?>*/var BASE_URL = "";var CODE_DIR = "";

function init() {
	//correctPNG(); we use iepngfix.htc instead
	initRollovers();
	initTooltips();
	initPopups();
	//if ($$('a[rel^=lightbox]').first() != undefined) loadLightbox();
	
	try {Shadowbox.init();}
	catch (e) {}
	
	if ($$('div.rounded').first() != undefined) loadRounded();
}

function initPopups() {
	$$("a.lightbox_popup").each(function(a) {
		a.observe("click", function(e) {
			var el = e.element();
			var props = $A(el["rel"].split(":"));
			Shadowbox.open({
				player: 'iframe',
				title: props[1],
				content: props[0],
				width: props[2],
				height: props[3]
			});
			return false;
		});
	});
}

function initRollovers() {
	$$('img.rollover').each(function(img) {
		img.observe('mouseover', function(e) {
			var el = e.element();
			el['src'] = el['src'].gsub(/thumb/, 'hover');
		});
		img.observe('mouseout', function(e) {
			var el = e.element();
			el['src'] = el['src'].gsub(/hover/, 'thumb');
		});
	});
}

function initTooltips() {
	$$('.tooltip_icon').each(function(tip) {
		var id = tip['id'].sub(/^tooltip-/, '');
		var tooltip = 'tooltip_content-'+id;
		new Tip(tip, $(tooltip).innerHTML, {
			style:'creamy',
			viewport: true,
			stem: 'topLeft',
			hook: { tip: 'topLeft', mouse: true },
			offset: { x: 16, y: 16 }

		});
	});
}

Event.observe(window, 'load', init);

function loadResource(url) {
    var head = $$('head').first();
	if (url.endsWith('.js')) {
		var el = new Element('script', {type:'text/javascript', src:BASE_URL+'/'+CODE_DIR+'/js/'+url});
		head.insert(el);
	}
	else if (url.endsWith('.css')) {
		var el = new Element('link', {type:'text/css', rel:'stylesheet', href:BASE_URL+'/'+CODE_DIR+'/css/'+url});
		head.insert(el);
	}
}

function loadRounded() {
	loadResource('rounded_corners/rounded_corners.js');
	loadResource('rounded_corners/init.js');
	return;
}

function loadLightbox() {
	//loadResource('scriptaculous/effects.js');
	//loadResource('shadowbox/adapter/shadowbox-prototype.js');
	loadResource('shadowbox/shadowbox-2.0.js');
	loadResource('shadowbox/shadowbox.css');
	loadResource('shadowbox/load.js');
	return;
}

function ajaxRun(action, params, success, empty) {
	if (Object.isUndefined(success)) success = alert;
	if (Object.isUndefined(empty)) empty = alert;
	
    new Ajax.Request('/ajax/'+action, {
        method: 'post',
        parameters: params,
        onSuccess: function(transport) {
                response = transport.responseText.evalJSON() || null
				if (AJAX_DEBUG) alert("ACTION: "+action+"\n\n"+response);
                return (response ? success(response) : empty());
            }
        });
}

function correctPNG() {
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters)) {
	  for (var i=0; i<document.images.length; i++)
	  {
		 var img = document.images[i]
		 var imgName = img.src.toUpperCase()
		 if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		 {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		 }
	  }
   }    
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function submitForm(e) {
	$$('body')[0].setStyle({cursor:"wait"});
	var el = e.element();
	el.up('form').submit();
}

function openPictureWindow_Fever(imageName,imageWidth,imageHeight,alt,posLeft,posTop) {
	newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
	newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' alt='+alt+'>'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function pushToForm() {
	var FormDataArray = pushToForm.arguments;
	//var FormID = FormDataArray.shift();

	var ele = "";
	var val = "";
	for(var i=0; i < FormDataArray.length; i=i+2) {
		ele = FormDataArray[i];
		val = FormDataArray[i+1];
		if($(ele)) {
			if($(ele).type == "checkbox" && $(ele).value == val) 
				$(ele).checked = true;
			else 
				$(ele).value = val;
		}
		//alert(ele + " = " + val);
		//eval("document.form1."+ele+".value = \""+val+"\"");
	} // end for
}