﻿/*
 Some common functions.
**/
var CurrentSelectedRecommendation = "";
var CurrentSelectedGallery = "";
var CurrentSelectedNav = "";
var SelectedSuffix = "_selected";

// This function gets an object id and sets
// it's CSS class as selected based on the following
// template - class[_selected]
// This function also gets the parameter name that
// holds the currently activated element	
function AddSelectedCSS(objId, currentSelectedParamName)
{			
	var currentlySelectedElement = eval(currentSelectedParamName);
	var obj = document.getElementById(objId);
	if (obj.className.indexOf(SelectedSuffix) == -1)
	{
		if (currentlySelectedElement != "")
		{
			ClearSelectedCSS(currentSelectedParamName);
		}
		obj.className = obj.className + SelectedSuffix;
		eval(currentSelectedParamName + " = \"" + objId + "\"");
	}
}

function ClearSelectedCSS(currentSelectedParamName)
{
	// This function receives a name of a paramater
	// the parameter contains the id of an object that is
	// currently selected and deselects it
	var currentlySelectedElement = eval(currentSelectedParamName);
	var obj = document.getElementById(currentlySelectedElement);
	try
	{
		obj.className = obj.className.substring(0, obj.className.length - (SelectedSuffix.length));
	}
	catch(e)
	{
		alert("error");
	}
}
/*
 genMOver(DOM Object obj)
 General mouse over function. Changes cursor to 'hand'.
**/
function genMOver(obj) {
	obj.style.cursor = 'pointer';
}
/*
 getURL(String url, String target)
 Changes document location or pops a new window up.
**/
function getURL(url, target) {
	if(target == '_blank') {
		// open a new window.
		window.open(url);
	} else {
		document.location = url;
	}
}
/*
 Footer functions:
 footerMOver(), footerMOut()
**/
function footerMOver(obj, color) {
	obj.style.cursor = "pointer";
	if(color == undefined) {
		obj.style.background = "#FFFFFF";
	} else {
		obj.style.background = color;
	}
}
function footerMOut(obj, color) {
	if(color == undefined) {
		obj.style.background = "#B9C5C9";
	} else {
		obj.style.background = color;
	}
}
/*
 articleImageSlider()
**/
function articleImageSlider(id) {
	try
	{
		this.id				= id;
		this.preloadImages	= false;
		this.objImage		= document.getElementById(this.id + "_image");
		this.objTitle		= document.getElementById(this.id + "_title");
		this.objAuthor		= document.getElementById(this.id + "_author");
		this.currentImage	= 0;
		this.totalItems		= 0;
		this.items			= new Array();
		this.addItem		= articleImageSliderAddItem;
		this.setItem		= articleImageSliderSetItem;
		this.next			= articleImageSliderNext;
		this.prev			= articleImageSliderPrev;
		this.getTotalItems	= articleImageSliderGetTotalItems;
		this.getCurrent		= articleImageSliderGetCurrent;
		this.setCurrent		= articleImageSliderSetCurrent;
	}
	catch(e)
	{
		
	}
	
}
function articleImageSliderAddItem(imgSrc, title, author) {
	//alert(author);
	// Create a new item array.
	this.items[this.totalItems] = new Array();
	
	// Save title and author.
	this.items[this.totalItems]["title"] = title;
	this.items[this.totalItems]["author"] = author;
	
	// Save image.
	if(this.preloadImages) {
		this.items[this.totalItems]["img"] = new Image();
		this.item[this.totalItems]["img"].src = imgSrc;
	} else {
		this.items[this.totalItems]["img"] =  imgSrc;
	}
	this.totalItems += 1;
}
function articleImageSliderSetItem(id) {
	try
	{
		if(id == undefined || (id < 0) || (id >= this.totalItems)) {
			id = 0;
		}
		this.currentItem = id;
		// Set Author and Title.
		this.objTitle.innerHTML		= this.items[id]["title"];
		if(this.items[id]["author"] != "") {
			this.objAuthor.innerHTML	= "צילום: " + this.items[id]["author"];
		} else {
			this.objAuthor.innerHTML	= "&nbsp;";
		}
		
		// Set Image.
		if(this.preloadImages) {
			this.objImage.src = this.items[id]["img"].src;
		} else {
			this.objImage.src = this.items[id]["img"];
		}
	}
	catch(e)
	{
	
	}
}
function articleImageSliderNext() {
	this.currentItem += 1;
	if(this.currentItem >= this.totalItems) {
		this.currentItem = 0;
	}
	this.setItem(this.currentItem);
}
function articleImageSliderPrev() {
	this.currentItem-= 1;
	if(this.currentItem < 0) {
		this.currentItem = this.totalItems - 1;
	}
	this.setItem(this.currentItem);
}
function articleImageSliderGetTotalItems() {
	return(this.totalItems);
}
function articleImageSliderGetCurrent() {
	return(this.currentItem);
}
function articleImageSliderSetCurrent(current) {
	this.currentItem = current;
}


/*
	Script for enabling flash objects
*/
function EnableActiveX(Obj)
{
	
	if (navigator.appName == "Microsoft Internet Explorer") {
		
		po = Obj.parentNode;
		tags = po.innerHTML;
		po.removeChild(Obj);
		po.innerHTML = tags;
	}
}

function GlobalActiveXManager()
{
	if (navigator.appName == "Microsoft Internet Explorer") {
		var actvx = new Array(3);
		actvx[0] = "object";
		actvx[1] = "embed";
		actvx[2] = "applet";
		for (n = 0; n < actvx.length; n++) {
			ro = document.getElementsByTagName(actvx[n]);
			for (i = 0; i < ro.length; i++ ) {
				EnableActiveX(ro[i]);
			}
		}
	}
}
	
/* ACCESSIBLE POP UP */
/* 
   strType options:
   * console - resizable
   * fixed - non-resizable
   * elastic - full featured window  
   
   If JavaScript is disabled the popup would still open ("_blank")
 */
function popUp(strURL,strType,strHeight,strWidth) {
	var strDiamentions="";
	var strPosition="";
	var strWindowStyle="";
    var strOptions="";
    
    // set style
    if (strType=="console") strWindowStyle="resizable";
    if (strType=="fixed") strWindowStyle="status";
    if (strType=="elastic") strWindowStyle="toolbar,menubar,scrollbars,resizable,location";
    // set position
    var l = (screen.width - strWidth) / 2;
	var t = (screen.height - strHeight) / 2;
    strPosition = 'top='+t+',left='+l+'w';
    strDiamentions ="height="+strHeight+",width="+strWidth;
    strOptions= strWindowStyle + "," + strDiamentions + "," + strPosition;
    
    window.open(strURL, 'newWin', strOptions);
}
