/***************************************************************
*  Copyright notice
*
*  (c) 2004 Pavlenko Zorik (zorik@zorik.net)
*  All rights reserved
*	you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/



function ga() { // start class ga
	/*
	 * http://simonwillison.net/2004/May/26/addLoadEvent/
	 * The addLoadEvent function takes as an argument another function which should be executed
	 *  once the page has loaded. Unlike assigning directly to window.onload, the function adds
	 *  the event in such a way that any previously added onload functions will be executed first.
	 * */
	this.initWindow = function() {
		try {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = function() {
					ga.init();
				}
			} else {
				window.onload = function() {
					if (oldonload) {
						oldonload();
					}
					ga.init();
				}
			}
		} catch(err) {
			this.errorAlert(err,"initWindow");
		}
	}
	this.init=function() {
		// attach fade effect to nav_land
		$(".item").bind("mouseover",ga.navland_mouseover);
		$(".item").bind("mouseout",ga.navland_mouseout);
		if (document.all) { // is IE
			$(".item").css("filter","progid:DXImageTransform.Microsoft.Fade(duration=0.25,overlap=1.0)");
		}
	}


	this.navland_mouseover=function(event) {
		if (document.all) { // is IE
			if (!$(event.target).hasClass("active")&&!$(event.target).hasClass("last_active")) {
				event.target.filters[0].Apply();
				if ($(event.target).hasClass("last")) {
					$(event.target).css("background-image","url(\"/fileadmin/template/gertner-arch2/images/nav_red_last.gif\")");
				} else {
					$(event.target).css("background-image","url(\"/fileadmin/template/gertner-arch2/images/nav_red.gif\")");
				}
				event.target.filters[0].Play();
			}
		}
	}
	this.navland_mouseout=function(event) {
		if (document.all) { // is IE
			if (!$(event.target).hasClass("active")&&!$(event.target).hasClass("last_active")) {
				event.target.filters[0].Apply();
				if ($(event.target).hasClass("last")) {
					$(event.target).css("background-image","url(\"/fileadmin/template/gertner-arch2/images/nav_black_last.gif\")");
				} else {
					$(event.target).css("background-image","url(\"/fileadmin/template/gertner-arch2/images/nav_black.gif\")");
				}
				event.target.filters[0].Play();
			}
		}
	}


	this.gallerySetPic=function (idImg) {
		if (document.all) { // is IE
			$("#item_gal_big").css("filter","progid:DXImageTransform.Microsoft.Fade(duration=0.25,overlap=1.0)");
			$("#item_gal_big").get(0).filters[0].Apply();
		}
		document.getElementById("item_gal_big").innerHTML = document.getElementById(idImg).innerHTML;
		if (document.all) { // is IE
			$("#item_gal_big").get(0).filters[0].Play();
		}
	}

	this.errorAlert = function(err,fCaller) {
		txt = "There was an error on this page.\n\n";
		txt+="Error description: "+fCaller+"()-" + err.description + "\n\n";
		txt+="Click OK to continue.\n\n";
		alert(txt);
	}

	/*
	 * BOOKMARK function
	 * */
	 this.bookmark = function() {
	 	var urlAddress = location.href;
	 	var pageName = document.title;

		if (window.external) {
			window.external.AddFavorite(urlAddress,pageName)
		} else {
			alert("Sorry! Your browser doesn't support this function.");
		}
	 }

	 /*
	  * EMAIL function
	  * */
	this.email = function() {
		var daReferrer = document.referrer;
		var email = "";
		var subject = "Gertner Architects website";
		var body_message = "%0D%0D%0D%0DInteresting webpage - \""+document.title+"\" at "+daReferrer+" %0D%0D;";

		var mailto_link = 'mailto:'+email+'?subject='+subject+'&body='+body_message;

		win = window.open(mailto_link,'emailWindow');
		if (win && win.open &&!win.closed) win.close();
	}

	 /*
	  * PRINT function
	  * */
	this.print = function() {
		window.print();
	}
} // end class ga

ga = new ga();
ga.initWindow();

