var debug_mode = 0;
var flash = {};
	function getObject(objectId) {
		// cross-browser function to get an object's style object given its id
		if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
		} else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId);
		} else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
		} else {
		return false;
		}
	} // getObject


	function set_nd(nd, np, kat, id, mode) {
		if (debug_mode) alert('set_nd(nd:'+nd+', np:'+np+', kat:'+kat+', id:'+id+', mode:'+mode+')');
		var konfig4=getObject("konfig4");
		konfig4.SetVariable("nd", nd);
		cur_nd=nd;
		cur_np=np;
		cur_id=id;
		//parent.cur_kat=kat;
		if (debug_mode) alert('flash.GetVariable(nd:'+parent.konfig4.GetVariable('nd')+'), flash.GetVariable(np:'+parent.konfig4.GetVariable('np')+')');
		$(".info_bar").html('<b>Trwa ładowanie...</b>');
		$(".info_bar").load("wirtualna_przymierzalnia,b,info,"+mode+","+np+","+nd+","+id+".html");
		// testowo wylaczane **********************************
		//parent.rooms.location.href='frame_right.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id;


	}

	function set_np(np, nd, kat, id, mode){
    if (debug_mode) alert('set_np(np:'+np+', nd:'+nd+', kat:'+kat+', id:'+id+', mode:'+mode+')');
		var konfig4=getObject("konfig4");
		konfig4.SetVariable("np", np);
		cur_np=np;
		//parent.cur_kat=kat;
		if (debug_mode) alert('flash.GetVariable(nd:'+parent.konfig4.GetVariable('nd')+'), flash.GetVariable(np:'+parent.konfig4.GetVariable('np')+'), flash.GetVariable(nda:'+parent.konfig4.GetVariable('nda')+')');
		//parent.carpet_list.location.href='frame.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id+'#L'+nd;

		// testowo wylaczane **********************************
		//location.href='frame_right.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id;
  }

	function reloadMode(np, nd, kat, id, mode){
		if (debug_mode) alert('reloadMode(np:'+np+', nd:'+nd+', kat:'+kat+', id:'+id+', mode:'+mode+')');
		var konfig4=parent.getObject(konfig4);
		konfig4.SetVariable("np", np);
		parent.cur_np=np;
		if (debug_mode) alert('flash.GetVariable(nd:'+parent.flash.GetVariable('nd')+'), flash.GetVariable(np:'+parent.flash.GetVariable('np')+'), flash.GetVariable(nda:'+parent.flash.GetVariable('nda')+')');
		parent.location.href='configurator.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id;
	}

/* test... ta funkcja jest chyba niepotrzebna... tak, jest niepotrzeban

	function initFlash(ob, nd, np, kat, id, mode){
		if (debug_mode) alert('initFlash(ob:'+ob+', nd:'+nd+', np:'+np+', kat:'+kat+', id:'+id+', mode:'+mode+')');
		flash.SetVariable("nd", nd);
		flash.SetVariable("np", np);
    	cur_nd = nd;
		cur_id = id;
		cur_mode=mode;
		cur_np=np;
		cur_kat=kat;
		if (debug_mode) alert('flash.GetVariable(nd:'+flash.GetVariable('nd')+'), flash.GetVariable(np:'+flash.GetVariable('np')+')');

		// testowo wylaczane **********************************
		//carpet_list.location.href='frame.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id+'#L'+nd;
		//rooms.location.href='frame_right.php?mode='+mode+'&nd='+nd+'&np='+np+'&kat='+kat+'&id='+id;
	}
*/

	function loadAllStiles(ob, nd, np, kat, id, mode, kat2){
		if (debug_mode) alert('loadAllStiles(ob:'+ob+', nd:'+nd+', np:'+np+', kat:'+kat+', id:'+id+', mode:'+mode+', kat2:'+kat2+')');
		cur_kat=kat;
		location.href='wirtualna_przymierzalnia,'+mode+','+np+','+nd+','+kat+','+id+'.html#L'+nd;
		//location.href='configurator.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat2+'&id='+id;
		//rooms.location.href='frame_right.php?mode='+mode+'&nd='+nd+'&np='+np+'&kat='+kat+'&id='+id;
	}

	function showDetails(id){
		if(!id) {
			location.href='index.php';
		} else {
			location.href='produkt,,'+id+'.html';
		}
	}

	function loadPrintMe(id)
	{
		if(!id) {
			opener.location.href='index.php';
		} else {
			window.open('print.php?id='+id, 'print', 'width=700,height=500,resizable=1,scrollbars=yes,menubar=no');
		}
	}

	/* type : 1 - drukowanie, 2 - twoje dywany */
	function current_link(nd, np, kat, id, mode, type, pokoj){
		var link_1;
		if(type == 1) {
			if(mode == 3) {
				link_1 = 'print,wirtualna_przymierzalnia,'+mode+','+np+','+nd+','+kat+','+id+','+pokoj+'.html#'+np;				
				var newWindow = window.open(link_1, '_blank');
			    newWindow.focus();
				return;
			} else {
				link_1 = 'print,wirtualna_przymierzalnia,'+mode+','+np+','+nd+','+kat+','+id+'.html#'+np;
				var newWindow = window.open(link_1, '_blank');
			    newWindow.focus();
				return;				
			}
		} else if(type == 2) {
			link_1 = 'twoje,wirtualna_przymierzalnia,'+mode+','+np+','+nd+','+kat+','+id+'.html';
		} else  {
			link_1 = 'wirtualna_przymierzalnia,'+mode+','+np+','+nd+','+kat+','+id+'.html';
		}
		if (debug_mode) alert(link_1);
		location.href=link_1;
	}


	function print_room(nd, np, kat, id, mode, type, pokoj) {
		var konfig4=getObject("konfig4");
		var x = konfig4.GetVariable("x");
		var y = konfig4.GetVariable("y");
		var sc = konfig4.GetVariable("sc");
		var pozx = konfig4.TGetProperty("poligon_mc", 0);
		var pozy = konfig4.TGetProperty("poligon_mc", 1);
		//alert('pozx: '+pozx+' pozy: '+pozy+' x: '+x+' y: '+y+' sc: '+sc);
		link_1 = 'index.php?module=dywany&theme=print&type=print_dywan&mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id+'&pokoj='+pokoj+'&x='+x+'&y='+y+'&sc='+sc+'&pozx='+pozx+'&pozy='+pozy;
		var newWindow = window.open(link_1, '_blank');
		newWindow.focus();
		return;
	}

	function setActive(obj)
	{
	  clearSelection();
	  if (debug_mode) alert('IE only: '+obj.outerHTML);
		obj.className = 'img_button2';

	}

	function clearSelection(con)
	{
	if (!con) var con = parent.carpet_list.document.getElementById('dywany');
		if (!con) return;

    if (!con.hasChildNodes()) return;

		var items = con.childNodes;
		var itemsCount = items.length;
		if (!itemsCount) return false;

    for (var it=0; it<itemsCount; it++)
    		{
    			var oItemTag = items[it];
    			if(oItemTag.tagName == 'IMG')
    			{
    				if (debug_mode) alert(oItemTag.className);
    				oItemTag.className = 'img_button';
    				if (debug_mode) alert(oItemTag.className);
    			}
    			clearSelection(oItemTag);
    	}
  }

	function set_active_nd(nd, np, kat, id, mode){
        location.href='frame.php?mode='+mode+'&np='+np+'&nd='+nd+'&kat='+kat+'&id='+id+'#L'+nd;
    }


