/**
* @author Stayko Dimitrov
* @version 1.0
*
* menu.js
* Modification History  :
*
* 1.0 	28/02/07 10:43	sdd 	Initial
*/

// Screen Height
var hght = screen.availHeight;
// Define the left offset from the mouse.
var MouseOffset = 8;

function openImage (site, settings) {
		var imageViewWindow = window.open(site,"imageViewWindow",settings + "location=no,toolbar=no,status=no,resizeable=yes,scrollbars=no,top=50,left=50");
		imageViewWindow.focus();
}

function go_config_top () {
	window.open(document.config.configurator.value, "_blank", "location=no,toolbar=no,status=yes,resizeable=yes,scrollbars=yes,width=620,screenX=1,screenY=1,left=1,top=1");
	document.config.configurator.value = "Select"
}

function go_config (tip, id) {
	window.open("config/?type=" + tip + "&id=" + id, "_blank", "location=no,toolbar=no,status=yes,resizeable=no,scrollbars=yes,width=620,height="+hght+",screenX=1,screenY=1,left=1,top=1");
	document.config.configurator.value = "Select"
}

function print (t) {
	window.open("print.php?id=" +t,"_blank","location=no,toolbar=no,status=yes,scrollbars=yes, width=606,height="+hght+",screenX=1, screenY=1,left=1,top=1,")
}

// Checks Mail
function is_valid_email(form, element) {
	if ((document.forms[form].elements[element].value.indexOf("@")<1) || (((document.forms[form].elements[element].value.lastIndexOf("."))-(document.forms[form].elements[element].value.indexOf("@")))<2) || (((document.forms[form].elements[element].value.length-1)-(document.forms[form].elements[element].value.lastIndexOf("."))))>4 || (((document.forms[form].elements[element].value.length-1)-(document.forms[form].elements[element].value.lastIndexOf(".")))<2) || document.forms[form].elements[element].value.indexOf("@") != document.forms[form].elements[element].value.lastIndexOf("@") || document.forms[form].elements[element].value.indexOf(" ") != -1 || document.forms[form].elements[element].value.indexOf(";") != -1 || document.forms[form].elements[element].value.indexOf(",") != -1) {
		return false;
	} else {
		return true
	}
}

// Checks email for Newsletter Registration
function check_data(lang) {
	switch (lang) {
		case 'BG':
			var empty = 'Полето "email" е празно.';
			var invalid = 'Съдържанието на полето "email" е невалидно.';
		break;
		case 'RU':
			var empty = 'Введите email.';
			var invalid = 'Содержание поля "email" невалидно.';
		break;
		case 'EN':
			var empty = 'The field "email" is empty.';
			var invalid = 'The content of the field "email" is invalid.';
		break;
		case 'ES':
			var empty = 'The field "email" is empty.';
			var invalid = 'The content of the field "email" is invalid.';
		break;
	}
	if (document.forms['loginform_newsletter'].nemail.value == '') {
		alert(empty);
		return false;
	} else  {
		if (!is_valid_email('loginform_newsletter', 'nemail')) {
			alert(invalid);
			return false;
		} else {
			document.forms['loginform_newsletter'].submit();
		}
	}
}

function check_login(lang) {
	switch (lang) {
		case 'BG':
			var username = 'Полето "име" е празно.';
			var invalid = 'Съдържанието на полето "име" е невалидно.';
			var password = 'Полето "парола" е празно.';
		break;
		case 'RU':
			var username = 'Введите имя.';
			var invalid = 'Содержание поля "имя" невалидно.';
			var password = 'Введите пароль.';
		break;
		case 'EN':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
		break;
		case 'ES':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
		break;
	}
	if (document.forms['loginform'].lusername.value == '') {
		alert(username);
		return false;
	} else if (!is_valid_email('loginform', 'lusername')) {
		alert(invalid);
		return false;
	} else {
		if (document.forms['loginform'].lpassword.value == '') {
			alert(password);
			return false;
		} else {
			document.forms['loginform'].submit();
		}
	}
}

function check_big_login(lang) {
	switch (lang) {
		case 'BG':
			var username = 'Полето "име" е празно.';
			var invalid = 'Съдържанието на полето "име" е невалидно.';
			var password = 'Полето "парола" е празно.';
		break;
		case 'RU':
			var username = 'Введите имя.';
			var invalid = 'Содержание поля "имя" невалидно.';
			var password = 'Введите пароль.';
		break;
		case 'EN':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
		break;
		case 'ES':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
		break;
	}
	if (document.forms['registerform'].lusername.value == '') {
		alert(username);
		return false;
	} else if (!is_valid_email('registerform', 'lusername')) {
		alert(invalid);
		return false;
	} else {
		if (document.forms['registerform'].lpassword.value == '') {
			alert(password);
			return false;
		} else {
			document.forms['registerform'].submit();
		}
	}
}

function check_register(lang) {
	switch (lang) {
		case 'BG':
			var username = 'Полето "потребителско име" е празно.';
			var invalid = 'Съдържанието на полето "потребителско име" е невалидно.';
			var password = 'Полето "парола" е празно.';
			var password1 = 'Полето "повторете паролата" е празно.';
			var different = 'Паролите, които сте въвели са различни.';
			var name = 'Полето "име" е празно.';
			var family = 'Полето "фамилия" е празно.';
			var country = 'Полето "държава" е празно.';
			var city = 'Полето "град" е празно.';
			var verificationcode = 'Въведете кода от изображението.';
		break;
		case 'RU':
			var username = 'Введите имя.';
			var invalid = 'Содержание поля "имя" невалидно.';
			var password = 'Введите пароль.';
			var password1 = 'Введите потверждение пароли.';
			var different = 'Несоответствующие пароли.';
			var name = 'Введите имя.';
			var family = 'Введите фамилия.';
			var country = 'Введите страна.';
			var city = 'Введите город.';
			var verificationcode = 'Введите число, которое вы видите.';
		break;
		case 'EN':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
			var password1 = 'The field "re-type password" is empty.';
			var different = 'The passwords you entered are different.';
			var name = 'The field "name" is empty.';
			var family = 'The field "family" is empty.';
			var country = 'The field "country" is empty.';
			var city = 'The field "city" is empty.';
			var verificationcode = 'Enter the code from the picture.';
		break;
		case 'ES':
			var username = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var password = 'The field "password" is empty.';
			var password1 = 'The field "re-type password" is empty.';
			var different = 'The passwords you entered are different.';
			var name = 'The field "name" is empty.';
			var family = 'The field "family" is empty.';
			var country = 'The field "country" is empty.';
			var city = 'The field "city" is empty.';
			var verificationcode = 'Enter the code from the picture.';
		break;
	}
	if (document.forms['registerform'].username.value == '') {
		alert(username);
		return false;
	} else if (!is_valid_email('registerform', 'username')) {
		alert(invalid);
		return false;
	} else if (document.forms['registerform'].password.value == '') {
		alert(password);
		return false;
	} else if (document.forms['registerform'].password1.value == '') {
		alert(password1);
		return false;
	} else if (document.forms['registerform'].password.value != document.forms['registerform'].password1.value) {
		alert(different);
		return false;
	} else if (document.forms['registerform'].name.value == '') {
		alert(name);
		return false;
	} else if (document.forms['registerform'].family.value == '') {
		alert(family);
		return false;
	} else if (document.forms['registerform'].country.value == '') {
		alert(country);
		return false;
	} else if (document.forms['registerform'].city.value == '') {
		alert(city);
		return false;
	} else if (document.forms['registerform'].verificationcode.value == '') {
		alert(verificationcode);
		return false;
	} else {
		document.forms['registerform'].submit();
	}
}

function check_profile(lang) {
	switch (lang) {
		case 'BG':
			var password = 'Полето "стара парола" е празно.';
			var different = 'Паролите, които сте въвели са различни.';
			var name = 'Полето "име" е празно.';
			var family = 'Полето "фамилия" е празно.';
			var country = 'Полето "държава" е празно.';
			var city = 'Полето "град" е празно.';
		break;
		case 'RU':
			var password = 'Введите старая пароль.';
			var different = 'Несоответствующие пароли.';
			var name = 'Введите имя.';
			var family = 'Введите фамилия.';
			var country = 'Введите страна.';
			var city = 'Введите город.';
		break;
		case 'EN':
			var password = 'The field "old password" is empty.';
			var different = 'The passwords you entered are different.';
			var name = 'The field "name" is empty.';
			var family = 'The field "family" is empty.';
			var country = 'The field "country" is empty.';
			var city = 'The field "city" is empty.';
		break;
		case 'ES':
			var password = 'The field "old password" is empty.';
			var different = 'The passwords you entered are different.';
			var name = 'The field "name" is empty.';
			var family = 'The field "family" is empty.';
			var country = 'The field "country" is empty.';
			var city = 'The field "city" is empty.';
		break;
	}
	if (document.forms['registerform'].password.value == '' && document.forms['registerform'].password1.value != '' && document.forms['registerform'].password2.value != '') {
		alert(password);
		return false;
	} else if (document.forms['registerform'].password1.value != document.forms['registerform'].password2.value) {
		alert(different);
		return false;
	} else if (document.forms['registerform'].name.value == '') {
		alert(name);
		return false;
	} else if (document.forms['registerform'].family.value == '') {
		alert(family);
		return false;
	} else if (document.forms['registerform'].country.value == '') {
		alert(country);
		return false;
	} else if (document.forms['registerform'].city.value == '') {
		alert(city);
		return false;
	} else {
		document.forms['registerform'].submit();
	}
}

function check_username(lang) {
	switch (lang) {
		case 'BG':
			var pusername = 'Полето "потребителско име" е празно.';
			var invalid = 'Съдържанието на полето "потребителско име" е невалидно.';
			var verificationcode = 'Въведете кода от изображението.';
		break;
		case 'RU':
			var pusername = 'Введите имя.';
			var invalid = 'Содержание поля "имя" невалидно.';
			var verificationcode = 'Введите число, которое вы видите.';
		break;
		case 'EN':
			var pusername = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var verificationcode = 'Enter the code from the picture.';
		break;
		case 'ES':
			var pusername = 'The field "username" is empty.';
			var invalid = 'The content of the field "username" is invalid.';
			var verificationcode = 'Enter the code from the picture.';
		break;
	}
	if (document.forms['passwordform'].pusername.value == '') {
		alert(pusername);
		return false;
	} else if (!is_valid_email('passwordform', 'pusername')) {
		alert(invalid);
		return false;
	} else if (document.forms['passwordform'].verificationcode.value == '') {
		alert(verificationcode);
		return false;
	} else {
		document.forms['passwordform'].submit();
	}
}

// Check CV Form
function check_cv(lang) {
	switch (lang) {
		case 'BG':
			var name = 'Полето "Име и фамилия" е празно.';
			var age = 'Полето "Възраст" е празно.';
			var email = 'Полето "Email" е празно.';
			var invalid = 'Съдържанието на полето "Email" е невалидно.';
			var country = 'Полето "Страна" е празно.';
			var education = 'Полето "Вид образование" е празно.';
			var computer_skills = 'Полето "Компютърна грамотност" е празно.';
			var preferences = 'Полето "Тип заетост" е празно.';
			var job_category = 'Полето "Предпочитана категория работа" е празно.';
			var salary = 'Полето "Очаквано мес. заплащане" е празно.';
		break;
		case 'RU':
			var name = 'Введите "Имя и фамилия".';
			var age = 'Введите "Возраст".';
			var email = 'Введите "Email".';
			var invalid = 'Содержание поля "Email" невалидно.';
			var country = 'Введите "Государство".';
			var education = 'Введите "Уровень образования".';
			var computer_skills = 'Введите "Уровень компьютерной грамотности".';
			var preferences = 'Введите "Предпочитаемый вид работы".';
			var job_category = 'Введите "Желаемая должность".';
			var salary = 'Введите "Желанная заработная плата".';
		break;
		case 'EN':
			var name = 'The field "Full Name" is empty.';
			var age = 'The field "Age" is empty.';
			var email = 'The field "Email" is empty.';
			var invalid = 'The content of the field "Email" is invalid.';
			var country = 'The field "Country" is empty.';
			var education = 'The field "Education type" is empty.';
			var computer_skills = 'The field "Computer Skills" is empty.';
			var preferences = 'The field "Preferences" is empty.';
			var job_category = 'The field "Preferable Job Category" is empty.';
			var salary = 'The field "Expected Salary" is empty.';
		break;
		case 'ES':
			var name = 'The field "Full Name" is empty.';
			var age = 'The field "Age" is empty.';
			var email = 'The field "Email" is empty.';
			var invalid = 'The content of the field "Email" is invalid.';
			var country = 'The field "Country" is empty.';
			var education = 'The field "Education type" is empty.';
			var computer_skills = 'The field "Computer Skills" is empty.';
			var preferences = 'The field "Preferences" is empty.';
			var job_category = 'The field "Preferable Job Category" is empty.';
			var salary = 'The field "Expected Salary" is empty.';
		break;
	}
	if (document.forms['cv_form'].name.value == '') {
		alert(name);
		return false;
	} else if (document.forms['cv_form'].age.value == '') {
		alert(age);
		return false;
	} else if (document.forms['cv_form'].email.value == '') {
		alert(email);
		return false;
	} else if (!is_valid_email('cv_form', 'email')) {
		alert(invalid);
		return false;
	} else if (document.forms['cv_form'].country.value == '') {
		alert(country);
		return false;
	} else if (document.forms['cv_form'].education.value == '') {
		alert(education);
		return false;
	} else if (document.forms['cv_form'].computer_skills.value == '') {
		alert(computer_skills);
		return false;
	} else if (document.forms['cv_form'].preferences.value == '') {
		alert(preferences);
		return false;
	} else if (document.forms['cv_form'].job_category.value == '') {
		alert(job_category);
		return false;
	} else if (document.forms['cv_form'].currency.value == '' || document.forms['cv_form'].salary.value == '') {
		alert(salary);
		return false;
	} else {
		document.forms['cv_form'].submit();
	}
}

// Finds the identificator of an instance, no matter of the browser used.
function FindID (id) {
	var o=null;
	if (!(o=document[id]) && document.all && (o=document.all[id])) o = o.style;
	else if (!o && document.layers) o=document.layers[id];
	else if (!o && document.getElementById && (o=document.getElementById(id))) o = o.style;
	return o;
}

function show (name, width) {
	var div_id = FindID(name);
	if (xMousePos != 0) {
		var xpos = xMousePos - MouseOffset - width;
		var ypos = yMousePos + MouseOffset;
		varOffset = ""+ypos+"px 0px 0px "+xpos+"px";
		div_id.margin = varOffset;
		div_id.visibility = "visible";
		document.forms[name].elements[name+'_x'].value = xpos;
		document.forms[name].elements[name+'_y'].value = ypos;
	}
}

function hide (name) {
	var div_id = FindID(name);
	if (div_id) div_id.visibility = "hidden";
}

function keep (name, x, y) {
	var div_id = FindID(name);
	varOffset = ""+y+"px 0px 0px "+x+"px";
	div_id.margin = varOffset;
	div_id.visibility = "visible";
}

// BEGIN  CAPTURE  MOUSE POSITION *************
var xMousePos = 0;
var yMousePos = 0;
var xMousePosMax = 0;
var yMousePosMax = 0;

var isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
var isIE    = (document.all && !isOPERA)? true : false;
var isDOM   = (document.getElementById && !isIE && !isOPERA)? true : false;

document.onmousedown = captureMousePosition;

function captureMousePosition (e) {
    if (isDOM) {
		xMousePos = e.pageX;
		yMousePos = e.pageY;
		xMousePosMax = window.innerWidth+window.pageXOffset;
		yMousePosMax = window.innerHeight+window.pageYOffset;
    } else {
		xMousePos = window.event.x+document.documentElement.scrollLeft;
		yMousePos = window.event.y+document.documentElement.scrollTop;
		xMousePosMax = document.documentElement.clientWidth+document.documentElement.scrollLeft;
		yMousePosMax = document.documentElement.clientHeight+document.documentElement.scrollTop;
    }
}
// END CAPTURE  MOUSE POSITION *************

function movieIsLoaded (theMovie) {
	if (typeof(theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
	else return false;
}

function load_movie(movie_name, movie_id) {
	if (movieIsLoaded(document.getElementById(movie_name))) {
		document.getElementById(movie_name).LoadMovie(0, 'images/header/'+movie_id);
	}
}

function set_rn (ref_no) {
	document.forms["ref_number"].elements["rn"].value = ref_no;
	document.forms["ref_number"].submit();
}

// -------------------------------------------------------------------
// Image Thumbnail Viewer Script- By Dynamic Drive, available at: http://www.dynamicdrive.com
// Last updated: Jan 22nd, 2007
// -------------------------------------------------------------------

var thumbnailviewer={
enableTitle: true, //Should "title" attribute of link be used as description?
enableAnimation: true, //Enable fading animation?
definefooter: '<div class="footerbar">close X</div>', //Define HTML for footer interface
defineLoading: '<img src="../images/loading.gif" /> Loading Image...', //Define HTML for "loading" div

/////////////No need to edit beyond here/////////////////////////

scrollbarwidth: 16,
opacitystring: 'filter:progid:DXImageTransform.Microsoft.alpha(opacity=10); -moz-opacity: 0.1; opacity: 0.1',
targetlinks:[], //Array to hold links with rel="thumbnail"

createthumbBox:function(){
//write out HTML for Image Thumbnail Viewer plus loading div
document.write('<div id="thumbBox" onClick="thumbnailviewer.closeit()" style="z-index: 100"><div id="thumbImage"></div>'+this.definefooter+'</div>')
document.write('<div id="thumbLoading">'+this.defineLoading+'</div>')
this.thumbBox=document.getElementById("thumbBox")
this.thumbImage=document.getElementById("thumbImage") //Reference div that holds the shown image
this.thumbLoading=document.getElementById("thumbLoading") //Reference "loading" div that will be shown while image is fetched
this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
},


centerDiv:function(divobj){ //Centers a div element on the page
var ie=document.all && !window.opera
var dom=document.getElementById
var scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset
var scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset
var docwidth=(ie)? this.standardbody.clientWidth : window.innerWidth-this.scrollbarwidth
var docheight=(ie)? this.standardbody.clientHeight: window.innerHeight
var docheightcomplete=(this.standardbody.offsetHeight>this.standardbody.scrollHeight)? this.standardbody.offsetHeight : this.standardbody.scrollHeight //Full scroll height of document
var objwidth=divobj.offsetWidth //width of div element
var objheight=divobj.offsetHeight //height of div element
var topposition=(docheight>objheight)? scroll_top+docheight/2-objheight/2+"px" : scroll_top+10+"px" //Vertical position of div element: Either centered, or if element height larger than viewpoint height, 10px from top of viewpoint
divobj.style.left=docwidth/2-objwidth/2+"px" //Center div element horizontally
divobj.style.top=Math.floor(parseInt(topposition))+"px"
divobj.style.visibility="visible"
},

showthumbBox:function(){ //Show ThumbBox div
this.centerDiv(this.thumbBox)
if (this.enableAnimation){ //If fading animation enabled
this.currentopacity=0.1 //Starting opacity value
this.opacitytimer=setInterval("thumbnailviewer.opacityanimation()", 20)
}
},


loadimage:function(link){ //Load image function that gets attached to each link on the page with rel="thumbnail"
if (this.thumbBox.style.visibility=="visible") //if thumbox is visible on the page already
this.closeit() //Hide it first (not doing so causes triggers some positioning bug in Firefox
var imageHTML='<img src="'+link.getAttribute("href")+'" style="'+this.opacitystring+'" />' //Construct HTML for shown image
if (this.enableTitle && link.getAttribute("title")) //Use title attr of the link as description?
imageHTML+='<br />'+link.getAttribute("title")
this.centerDiv(this.thumbLoading) //Center and display "loading" div while we set up the image to be shown
this.thumbImage.innerHTML=imageHTML //Populate thumbImage div with shown image's HTML (while still hidden)
this.featureImage=this.thumbImage.getElementsByTagName("img")[0] //Reference shown image itself
this.featureImage.onload=function(){ //When target image has completely loaded
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div
thumbnailviewer.showthumbBox() //Display "thumbbox" div to the world!
}
if (document.all && !window.createPopup) //Target IE5.0 browsers only. Address IE image cache not firing onload bug: panoramio.com/blog/onload-event/
this.featureImage.src=link.getAttribute("href")
this.featureImage.onerror=function(){ //If an error has occurred while loading the image to show
thumbnailviewer.thumbLoading.style.visibility="hidden" //Hide "loading" div, game over
}
},

setimgopacity:function(value){ //Sets the opacity of "thumbimage" div per the passed in value setting (0 to 1 and in between)
var targetobject=this.featureImage
if (targetobject.filters && targetobject.filters[0]){ //IE syntax
if (typeof targetobject.filters[0].opacity=="number") //IE6
targetobject.filters[0].opacity=value*100
else //IE 5.5
targetobject.style.filter="alpha(opacity="+value*100+")"
}
else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
targetobject.style.MozOpacity=value
else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
targetobject.style.opacity=value
else //Non of the above, stop opacity animation
this.stopanimation()
},

opacityanimation:function(){ //Gradually increase opacity function
this.setimgopacity(this.currentopacity)
this.currentopacity+=0.1
if (this.currentopacity>1)
this.stopanimation()
},

stopanimation:function(){
if (typeof this.opacitytimer!="undefined")
clearInterval(this.opacitytimer)
},


closeit:function(){ //Close "thumbbox" div function
this.stopanimation()
this.thumbBox.style.visibility="hidden"
this.thumbImage.innerHTML=""
this.thumbBox.style.left="-2000px"
this.thumbBox.style.top="-2000px"
},

cleanup:function(){ //Clean up routine on page unload
this.thumbLoading=null
if (this.featureImage) this.featureImage.onload=null
this.featureImage=null
this.thumbImage=null
for (var i=0; i<this.targetlinks.length; i++)
this.targetlinks[i].onclick=null
this.thumbBox=null
},

dotask:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false)
else if (target.attachEvent)
target.attachEvent(tasktype, functionref)
},

init:function(){ //Initialize thumbnail viewer script by scanning page and attaching appropriate function to links with rel="thumbnail"
if (!this.enableAnimation)
this.opacitystring=""
var pagelinks=document.getElementsByTagName("a")
for (var i=0; i<pagelinks.length; i++){ //BEGIN FOR LOOP
if (pagelinks[i].getAttribute("rel") && pagelinks[i].getAttribute("rel")=="thumbnail"){ //Begin if statement
pagelinks[i].onclick=function(){
thumbnailviewer.stopanimation() //Stop any currently running fade animation on "thumbbox" div before proceeding
thumbnailviewer.loadimage(this) //Load image
return false
}
this.targetlinks[this.targetlinks.length]=pagelinks[i] //store reference to target link
} //end if statement
} //END FOR LOOP
//Reposition "thumbbox" div when page is resized
this.dotask(window, function(){if (thumbnailviewer.thumbBox.style.visibility=="visible") thumbnailviewer.centerDiv(thumbnailviewer.thumbBox)}, "resize")


} //END init() function

}

thumbnailviewer.createthumbBox() //Output HTML for the image thumbnail viewer
thumbnailviewer.dotask(window, function(){thumbnailviewer.init()}, "load") //Initialize script on page load
thumbnailviewer.dotask(window, function(){thumbnailviewer.cleanup()}, "unload")