function returnHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'  
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

function CheckIsIE()
{
if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true;}
else { return false; }
}

function PrintThisPage()
{

if (CheckIsIE() == true)
{
document.document_lightbox.focus();
document.document_lightbox.print();
}
else
{
window.frames['document_lightbox'].focus();
window.frames['document_lightbox'].print();
}

} 

function closeGallery () {
	if ($("modal")) {
       $("modal").dispose();
	   $("gallery_lightbox").dispose();
       
    }
}

var toggleModal = function(section, lng, pic, options) {
	
    if ($("modal_container")) {
        $("modal_container").dispose();
        return false;
    }
    var options = $merge({
        zIndex: 100,
        opacity: .8,
        events: $empty(),
		backgroundColour:'#000000'
    }, options);
	var backgroundColour='#000000';
    if (!$type(backgroundColour) && !$("modal"))
        return false;
	   
	
	var modal = new Element("div", {
        id: "modal",
        styles: {
            position: "absolute",
            top: 0,
            left: 0,
            width: window.getScrollWidth(),
            height: window.getScrollHeight(),
            background: '#000000',
            "z-index": options.zIndex
        },
        opacity: 0,
        events: {
          click: function(){
			  $("modal").dispose();
			  $("gallery_lightbox").dispose();
       	}
     }
    }).inject(document.body);
	
	var dir = (lng=="hr")?"":"../";
	
    var myIFrame = new IFrame({
    id:'gallery_lightbox',
	allowTransparency:'true',
	
    src:dir+'pages/gallery.php?lng='+lng+'&section='+section+'&pic='+pic,
	frameborder:'0',
	opacity:0,
    styles: {
         width: '940px',
         height: '650px',
         border: '0px',
		 top: returnHeight()/2+$(window).getScroll().y
    },
    events: {
       
    }
	}).inject(document.body);
	
	new Fx.Tween(modal, {
		property: 'opacity',
		duration: 500, 
		transition: Fx.Transitions.Quart.easeInOut
	}).start(0.5);
	
	var tween = new Fx.Tween(myIFrame, {
		property: 'opacity',
		duration: 300, 
		transition: Fx.Transitions.Quart.easeInOut
	});

	tween.start.pass([0,1], tween).delay(400);
	
	$(window).addEvent('scroll',function() { 						
		myIFrame.setStyle('top', (returnHeight())/2+$(window).getScroll().y);		;	
	});

   // return container;
}
var iFrame;
var openDocument = function() {
	
	
	
   if ($("modal")) {
	   $("print_icon").dispose();
	   $("close_icon").dispose();
       $("modal").dispose();
	   $("document_lightbox").dispose();
	  
        return false;
    }

    var options = $merge({
        zIndex: 100,
        opacity: .8,
        events: $empty()
    }, options);
	   
	
	var modal = new Element("div", {
        id: "modal",
        styles: {
            position: "absolute",
            top: 0,
            left: 0,
            width: window.getScrollWidth(),
            height: window.getScrollHeight(),
            background: '#000000',
            "z-index": options.zIndex
        },
        opacity: 0,
   	   events: {
            click: function(){
			    $("print_icon").dispose();
	   			$("close_icon").dispose();
       			$("modal").dispose();
	   			$("document_lightbox").dispose();
       	  }
        }
    }).inject(document.body);
	
	var print_icon = new Element('div', {
    id: 'print_icon',
    html: "<img src='images/print_icon.gif' />",
    styles: {
		"z-index": options.zIndex+1,
		marginTop:-(returnHeight()-220)/2-31+$(window).getScroll().y,
	    marginLeft:340
    },
	opacity: 0,
    events: {
        'click': function(){
           PrintThisPage();
        }
    }
	}).inject(document.body);
	
	var close_icon = new Element('div', {
    id: 'close_icon',
    html: "<img src='images/close_icon.gif' />",
    styles: {
		"z-index": options.zIndex+2,
		marginTop:-(returnHeight()-220)/2-25+$(window).getScroll().y,
	    marginLeft:380
    },
	opacity: 0,
    events: {
        'click': function(){
            $("print_icon").dispose();
	   		$("close_icon").dispose();
       		$("modal").dispose();
	   		$("document_lightbox").dispose();
        }
    }
	}).inject(document.body);
	
	
	
	
     iFrame = new IFrame({
     id:'document_lightbox',
	 name:'document_lightbox',
     src:"http://www.youtube.com/embed/0pMEY6PKwCA",
     styles: {
         width: 800,
         height: returnHeight()-220,
	     marginTop:-(returnHeight()-220)/2+$(window).getScroll().y,
	     marginLeft:-400,
		 'background-color':'#ffffff'
     },
     opacity: 0,
     events: {
         load: function(){
         }
     }
	}).inject(document.body);
	
	new Fx.Tween(modal, {
		property: 'opacity',
		duration: 500, 
		transition: Fx.Transitions.Quart.easeInOut
	}).start(0.5);
	
	var tween = new Fx.Tween(iFrame, {
		property: 'opacity',
		duration: 300, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	var tween2 = new Fx.Tween(print_icon, {
		property: 'opacity',
		duration: 300, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	var tween3 = new Fx.Tween(close_icon, {
		property: 'opacity',
		duration: 300, 
		transition: Fx.Transitions.Quart.easeInOut
	});
	
	tween.start.pass([0,1], tween).delay(400);
	tween2.start.pass([0,1], tween2).delay(400);
	tween3.start.pass([0,1], tween3).delay(400);
	
	$(window).addEvent('scroll',function() { 						
		iFrame.setStyle('margin-top', -(returnHeight()-220)/2+$(window).getScroll().y);		
		close_icon.setStyle('margin-top', -(returnHeight()-220)/2-25+$(window).getScroll().y);	
		print_icon.setStyle('margin-top', -(returnHeight()-220)/2-31+$(window).getScroll().y);	
	});

}

var spatialplans = false;

var openDocumentFromMenu = function (doctarget) {
	
	var scroll = new Fx.Scroll(window, {
		wait: false,
		duration: 2500,
		offset: {'y': window.getScrollHeight()},
		transition: Fx.Transitions.Quad.easeInOut
	});

	if (section=="documents"){
		if (doctarget!="plans") {
			openDocument(doctarget);
		}else{
			scroll.toBottom();
		}
		spatialplans = false;
	}else{
		if (doctarget!="plans") {
			setTimeout(openDocument, 1100, doctarget, null);
		}else{
			spatialplans = true;
		}
	}
}
//
