// JavaScript Document
//WRITE FLASH CODE
function writeFlash(fFile, fTitle, fWidth, fHeight) {
	var codeFlash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+fWidth+'" height="'+fHeight+'" title="'+fTitle+'">';
	codeFlash += '<param name="movie" value="'+fFile+'" />';
	codeFlash += '<param name="quality" value="high" />';
	codeFlash += '<param name="wmode" value="transparent" />';
	codeFlash += '<embed src="'+fFile+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="'+fWidth+'" height="'+fHeight+'">';
	codeFlash += '</embed></object>';
	document.write(codeFlash);
}

// ADD EVENT TO OBJECT
function addEvent( obj, type, fn ){  // the add event function
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
	  obj["e"+type+fn] = fn;
	  obj[type+fn] = function() {
		obj["e"+type+fn]( window.event );
	  };
	  obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

// PRELOAD IMAGES
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_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_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 preload() {
	MM_preloadImages('images/nav_home_on.gif','images/nav_kontakt_on.gif','images/nav_o_nama_on.gif','images/nav_reference_on.gif','images/nav_ponuda_on.gif');
}

// ADD EVENT TO PRELOAD IMAGES
addEvent(window, 'load', preload);

// HANDLE MOUSE OVER IN MAIN MENU
// set images folder
var imgDir = 'images/';
// set mouse over images sufix
var imgSufix = '_on';
// set images type
var imgType = 'gif';
// set menu items
var navItems = new Array();
navItems.push('nav_home');
navItems.push('nav_o_nama');
navItems.push('nav_ponuda');
navItems.push('nav_reference');
navItems.push('nav_kontakt');


// over handling
function navOver(nav) {
	nav.src = imgDir+nav.id+imgSufix+'.'+imgType;
}
// out handling
function navOut(nav) {
	nav.src = imgDir+nav.id+'.'+imgType;
}

function myAlert(txt) {
	alert(txt);
}
// all together now! :)
function navHandle() {
	for(key in navItems) {
		nav = document.getElementById(navItems[key]);		
		if(nav != null) {			
			addEvent(nav, 'mouseover', function () { navOver(this); });
			addEvent(nav, 'mouseout', function () { navOut(this); });
		}
	}
}

// attach call to window
addEvent(window, 'load', navHandle);

// JavaScript Document
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}
var myWindow;
function openCenteredWindow(url, width, height) {
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",status,resizable,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}

// For charts
function openWin(loc, w, h) {
	var windowFeatures = "width=" + w + ",height=" + h + 
        ",status,resizable,scrollbars=yes";
	var newWin = window.open(loc, "subWind", windowFeatures);
	newWin.window.focus();
}