/*////////////////////////////////
//                              //
//                              //
//            Common            //
//                              //
//                              //
////////////////////////////////*/

function getFileName()
{
	var string = location.href.substring(location.href.lastIndexOf('/')+1);
	return string.substring(0,string.lastIndexOf('?'));
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?"));
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( 
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function getEventTarget(evt) {
	var targ = evt.target ? evt.target : evt.srcElement;

	if(targ !== null) {
		if(targ.nodeType == 3)
		{
			targ = targ.parentNode;
		}
	}

return targ;
}

function getElementsByClass(searchClass,num,node,tag) {
	var classElements = new Array();
	if ( node == null )
	{
		node = document;
	}
	if ( tag == null )
	{
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var senum = 0;
	var j=0;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0; j == 0 && i < elsLen; i++) {
		if (els[i].className)
		{
		if (els[i].className==searchClass) {
			if (senum==num)
			{
				classElements = els[i];
				j++;
			}
			senum++;
		}
		}
	}
	return classElements;
}

function goToUrl(url)
{
	url = url.replace(";:COLOR:;", setColor);
	var myUrls = window.location.href.split("#");
	var myUri = myUrls[0];
	var myanchor = "#"+url; 
	var myLocation = ''; 
	myLocation = myUri + myanchor; 
	loaded=false;
	window.location.href = myLocation;
	noClick = 'no';
	window_handler("load");
}

function getScrollBarWidth () {
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 === w2) 
	{
		w2 = outer.clientWidth;
	}
	document.body.removeChild (outer);
	
	return (w1 - w2);
}


/*////////////////////////////////
//                              //
//                              //
//          Set variables		//
//                              //
//                              //
////////////////////////////////*/


var informations;
var numOfAlbum;
var startImage;
var albumCount;
var glob_grid_size = 190;
var glob_mosaic_size = 85;
var glob_time = 0;
var glob_num = 0;
var glob_scrollbar;
var urlName = getFileName();
var urlView = getURLParam('view');
var albumName = getURLParam('album');
var stopratio;
var stopSizeH;
var stopSizeW;
var winW; 
var winH;
var imgW = 500;
var imgH = 350;
var imgNH;
var imgNW;
var ration = 0;
var setColor;
image_elements = new Array();
var  noClick;
var loaded=false;

/*////////////////////////////////
//                              //
//                              //
//         	image view  		//
//                              //
//                              //
////////////////////////////////*/

function image_view_load(imageName)
{
	informations = $('information').value.split(";");
	numOfAlbum = informations[0];
	startImage = informations[1];
	//$("img").style.width = '130px';
	
	color = getURLParam('color');
	
	var elem = $('imagecontainer');
	var bodyelem = document.getElementsByTagName('body')[0];
	var topElem = $('top');
	
	if(color=='White')
	{
		elem.style.backgroundColor = 'white';
		bodyelem.style.backgroundColor = 'white';
		topElem.style.borderBottomColor = 'rgb(0,0,0)';
	}
	if(color=='ltGrey')
	{
		elem.style.backgroundColor = 'rgb(150, 150, 150)';
		bodyelem.style.backgroundColor = 'rgb(150, 150, 150)';
		topElem.style.borderBottomColor = 'rgb(0,0,0)';
	}
	if(color=='dkGrey')
	{
		elem.style.backgroundColor = 'rgb(50, 50, 50)';
		bodyelem.style.backgroundColor = 'rgb(50, 50, 50)';
		topElem.style.borderBottomColor = 'rgb(150,150,150)';
	}
	if(color=='Black')
	{
		elem.style.backgroundColor = 'rgb(0, 0, 0)';
		bodyelem.style.backgroundColor = 'rgb(0, 0, 0)';
		topElem.style.borderBottomColor = 'rgb(150,150,150)';
	}
	image_view_resize(imageName);
	
	if (document.images)
    {
		preload_image_object = new Image();
		// set image url
		image_url = new Array();
		image_url[0] = "images/downloadhov.png";
		image_url[1] = "images/lefthov.png";
		image_url[2] = "images/righthov.png";
		image_url[3] = "images/infohov.png";
	
		var i = 0;
		for(i=0; i<=3; i++) 
		{
			preload_image_object.src = image_url[i];
		}
	}

	$("all").style.visibility = 'visible';
}

function image_view_resize(imagename)
{
	var image = $("img");	
	info = image.lang;
	
	var infos = info.split(";");
	
	imgW = infos[0]; 
	imgH = infos[1];
	ration = imgW/imgH;

	var local_winW = winW;
	var local_winH = winH;
	
	$('all').style.height = local_winH - 115;
	$('header_imageview').style.left = (local_winW-($('header_imageview').offsetWidth))/2+'px';
	if (ration>=1)//square/wide
	{		
		if (((local_winW-20)/ration)>=(local_winH-155))
		{
			image.width = (winH-155)*ration;
			image.height = winH-155;
		}
		else
		{
			image.height = (local_winW-20)/ration;
			image.width = (local_winW-20);
			image.style.marginTop = (((local_winH-155)-(image.offsetHeight))/2)+'px';
		}
		image.style.minHeight = 200/ration+'px';
		image.style.minWidth = 200+'px';
		var preload = new Image();
  		preload.src = "ajaxinfo/loadimage.php?image="+imagename+"&album="+albumName+"&height="+Math.round(image.height)+"&width="+Math.round(image.width);
		glob_num++;
		image_view_wait_image_load(preload,image, glob_num);
	}
	else//tall
	{
		if (((local_winW-20)/ration)>=(local_winH-155))
		{
			image.width = (local_winH-155)*ration;
			image.height = local_winH-155;
		}
		else
		{
			image.height = (local_winW-20)/ration;
			image.width = (local_winW-20);
		}
		image.style.minWidth = 200*ration+'px';
		image.style.minHeight = 200+'px';
		var preload = new Image();
  		preload.src = "ajaxinfo/loadimage.php?image="+imagename+"&album="+albumName+"&height="+Math.round(image.height)+"&width="+Math.round(image.width);
		glob_num++;
		image_view_wait_image_load(preload,image, glob_num);
	}
	$('controls').style.left = ((local_winW-440)/2)+'px';
	$('shareWindow').style.height = local_winH-180+'px';
	$('shareWindow').style.left = ((local_winW-620)/2)+'px';
}

function image_view_wait_image_load(preload,image,number)
{ 
	if(!preload.complete && number==glob_num)
	{ 
		var func = function() {image_view_wait_image_load(preload,image,number);};
		imgWait=setTimeout(func, 10);
	} 
	else{ 
		image.src = preload.src;
	} 
}

/*////////////////////////////////
//                              //
//                              //
//         	Album view  		//
//                              //
//                              //
////////////////////////////////*/

function album_view_load() {
	informations = $('information').value.split(";");
	numOfAlbum = informations[0];
	startImage = informations[1];
	setColor = getURLParam('color');
	if (setColor=='')
	{
		setColor = 'Black';	
	}
	album_view_resize('reflect');
	colorChange('click', setColor)
	if (urlView == 'mosaic')
	{
		mosaic_view_slider_resize(85);
		mosaic_view_slider_resize(85);
		$("bg").style.visibility = 'hidden';
		$("bg").style.margin = '0';
		$("bg").style.height = '0';
		$("view").style.visibility = 'visible';
	}
	if (urlView == 'grid')
	{
		$("bg").style.visibility = 'hidden';
		$("bg").style.margin = '0';
		$("bg").style.height = '0';
		$("bg").style.padding = '0';
		$("bg").style.display = 'none';
		$("view").style.visibility = 'visible';
		(function() 
		{
			var zoom_slider = $('zoom_slider');
			if(glob_grid_size=='')
			{
				glob_grid_size=190;
			}
			new Control.Slider(zoom_slider.down('.handle'), zoom_slider, 
			{
				range: $R(80, 300),
				sliderValue: glob_grid_size,
				onSlide: function(value) 
				{
					if(value==300 || value==80)
					{
						grid_view_resize_slider(value, 'reflect');
					}
					else
					{
						grid_view_resize_slider(value);
					}
					glob_grid_size = value;
				},
				onChange: function(value) 
				{ 
					if(value==300 || value==80)
					{
						grid_view_resize_slider(value, 'reflect');
					}
					else
					{
						grid_view_resize_slider(value);
					}
					glob_grid_size = value;
				}
			});
		})();		
	}
	if (urlView == 'mosaic')
	{
		if (glob_mosaic_size=='')
		{
			glob_mosaic_size=85;	
		}
		(function() 
		{
			var zoom_slider = $('zoom_slider');
	
			new Control.Slider(zoom_slider.down('.handle'), zoom_slider, 
			{
				range: $R(50, 120),
				sliderValue: glob_mosaic_size,
				onSlide: function(value) 
				{
					mosaic_view_slider_resize(value);
					mosaic_view_slider_resize(value);
					glob_mosaic_size = value;
				},
				onChange: function(value) 
				{
					mosaic_view_slider_resize(value);
					mosaic_view_slider_resize(value);
					glob_mosaic_size = value;
				}
			});
		})();
		mosaic_view_slider_resize(glob_mosaic_size);
		mosaic_view_add_new_image('image1');
	}
}

function album_view_resize(reflect)
{	
	var width;
	var local_winW = winW;
	var local_winH = winH;
	var scrollbar = glob_scrollbar;
	if(scrollbar==17)
	{
		scrollbar=0;
	}
	else if (scrollbar==15)
	{
		scrollbar -= 6;
	}
	if (urlView == 'grid')
	{
		$('imagesgrid').style.width = local_winW+'px';
		$('imagesgrid').style.height = (local_winH-97)+'px';
		grid_view_resize_slider(null, reflect);
		grid_view_resize_slider(null, reflect);
	}
	if (urlView == 'mosaic')
	{
		$('oneimage').style.width = local_winW-400+'px';
		$('oneimage').style.height = (local_winH-197)+'px';
		$('imagesmos').style.height = (local_winH-97)+'px';
		mosaic_view_add_new_image('none');
	}
	$('bottom').style.top = (local_winH-40)+'px';
	$('bottom').style.width = local_winW+'px';
}

function grid_view_resize_slider(value, update) {
	var imgSize = value || glob_grid_size;
	var local_winW = winW;
	var local_winH = winH;
	
	
	imgSize = parseInt(imgSize);
	
	var scrollbar = glob_scrollbar;
	
	var local_winW = local_winW-scrollbar;
	
	var minImgW = imgSize+20;
	
	var maxNum = local_winW/minImgW;
	
	maxNum = parseInt(maxNum); 
	
	var size = local_winW/maxNum;
	var op;
	
	size = parseInt(size);
	
	var margintop	=0;
	var toptimes	=1;
	var times		=0;
	var num			=0;
	
	glob_time++;
	
	image_elements = Array();
	
	while (num<numOfAlbum) 
	{
		imageelement = $('img'+num);
		element = $('div'+num);
		spelement = $('span'+num);
		inpelement = $('form'+num);
		textelement = $('text'+num);
		bgElem = $('imagesgrid');
		
		image_elements[num] = imageelement;
		
		info = element.lang;
		var mySplitResult = info.split(";");
		
		imageName = mySplitResult[0];
		orig_width = mySplitResult[1];
		orig_height = mySplitResult[2];
		thumbpath = mySplitResult[3];
		
		if (update=='reflect' || update=='resize')
		{
			var preload = new Image();
  			preload.src = thumbpath;
			grid_view_wait_image_load(preload, imageelement, num);
			Reflection.add(imageelement, { opacity: 1/4, height: 1/4 });
		}
		
		
		ratio = orig_width/orig_height;
		
		canvaselement = getElementsByClass('reflection', num);
		
		if (document.all && !window.opera) {
			changer=1;
		}
		else
		{
			changer=1/4;
		}
		
		if (times>=maxNum)
		{
			margintop = ((imgSize+(80/300)*imgSize)+20)*toptimes;
			times=0;
			toptimes++;
		}
		if (setColor=='White' || setColor=='ltGrey')
		{
			spelement.style.color = 'rgb(40, 40, 40)';	
			spelement.style.textShadow = 'rgb(255, 255, 255) 0px 0px 2px';
		}
		else {
			spelement.style.color = 'rgb(204, 204, 204)';
			spelement.style.textShadow = 'rgb(0, 0, 0) 0px 0px 2px';
		}
		if (ratio>=1)//wide
		{
			width = imgSize;
			height = width/ratio;
			element.style.width = size;
			element.style.left = size*times+((size-width)/2)+'px';
			//alert(imgSize);
			element.style.top = margintop+(imgSize+((50/300)*imgSize)-height)-90+'px';
			//alert('imgSize:'+imgSize+' margintop:'+margintop+' height:'+height);
			textelement.style.top = height+'px';
			textelement.style.width = width+'px';
			//textelement.style.height = (height/4)-1+'px';
			imageelement.width = width;
			imageelement.height = height;
			canvaselement.style.width = width+"px";
			canvaselement.style.height = height*changer+"px";
			miniW = 140;
			miniH = 140/ratio;
		}
		else
		{
			height = imgSize;
			height = (height+((50/300)*imgSize));
			width = height*ratio;
			marginleft = size*times;
			element.style.width = size;
			element.style.left = marginleft+((size-width)/2)+'px';
			element.style.top = margintop-0+'px';
			textelement.style.top = height+'px';
			textelement.style.width = width+'px';
			//textelement.style.height = (height/4)-1+'px';
			imageelement.height = height;
			imageelement.width = width;
			canvaselement.style.width = width+"px";
			canvaselement.style.height = height*changer+"px";
			miniH=140;
			miniW=140*ratio;
		}
		times++;
		num++;
	}
	lastNum=maxNum;
}

function mosaic_view_resize_center_image(elementname,newornot){
	var local_winW = winW;
	var local_winH = winH;
	imgW = imgNW;
	imgH = imgNH;
	
	var scrollbar = glob_scrollbar;
	
	if(scrollbar==17)
	{
		local_winH += 20;
		scrollbar=0;
	}
	else if (scrollbar==15)
	{
		scrollbar -= 6;
	}
	var image = $("img");	
	local_winW=local_winW-400-scrollbar;
	if (local_winW >= local_winH)//square/wide
	{
		if (((local_winW-20)/ration)>=(local_winH-180))
		{
			image.width = (local_winH-180)*ration;
			image.height = local_winH-180;
		}
		else
		{
			image.height = (local_winW-20)/ration;
			image.width = (local_winW-20);
		}
		image.src = "ajaxinfo/loadimage.php?image="+elementname+"&album="+albumName+"&height="+Math.round(image.height)+"&width="+Math.round(image.width);
		image.name = elementname;
		if (newornot!='none')
		{
		mosaic_view_wait_image_load(image);
		}
	}
	else//tall
	{	
		if (((local_winW-20)/ration)>=(local_winH-180))
		{
			image.width = (local_winH-180)*ration;
			image.height = local_winH-180;
		}
		else
		{
			image.height = (local_winW-20)/ration;
			image.width = (local_winW-20);
		}
		image.style.minWidth = 200*ration+'px';
		image.style.minHeight = 200+'px';
		image.src = "ajaxinfo/loadimage.php?image="+elementname+"&album="+albumName+"&height="+Math.round(image.height)+"&width="+Math.round(image.width);
		image.name = elementname;
		if (newornot!='none')
		{
		mosaic_view_wait_image_load(image);
		}
	}
}

function bottomMouseUp() {
	var func = function() {grid_view_resize_slider(glob_grid_size, 'reflect');};
	test=setTimeout(func, 20);
}

function grid_view_click_newimage(e) {
	var outside = 'out';
	var num=0;
	var wide;
	var tall;
	e = e || window.event;
	
	while (num<=numOfAlbum-1) 
	{
		image = 'img'+num;
		if(!clickedOutsideElement(image,e))
		{
			outside = 'in';
			id = image;
		}
		
		num++;
	}
	if (outside=='in')
	{
		var image = $(id);
		var filename = image.name;
		goToUrl("?image="+filename+"&album="+albumName+"&view=image&last=grid&color="+setColor);
	}
}

function mosaic_view_add_new_image(image)
{	
	if (image!='none')
	{
		var info = $(image).lang;
		var imgS = info.split(";");
		
	
		file = imgS[0]; 
		imgW = imgS[1];
		imgH = imgS[2];
		
		$('mosaic_photo_text').innerHTML = imgS[3];
			
		var ratio = imgW/imgH;
		ration = ratio;
		imgNW = imgW;
		imgNH = imgH;
	}
	else
	{
		var file = $('img').name;
	}
	mosaic_view_resize_center_image(file, image);
}

function grid_view_wait_image_load(preload, img, num)
{
	if(!preload.complete)
	{
		var func = function() {grid_view_wait_image_load(preload, img, num);};
		imgWait=setTimeout(func, 10);
	} 
	else{
		img.src = preload.src;
		Reflection.add(img, { opacity: 1/4, height: 1/4 });
	} 
}

function mosaic_view_wait_image_load(img)
{ 
	if(!img.complete)
	{ 
		img.style.visibility = 'hidden';
		imgWait=setTimeout('mosaic_view_wait_image_load(img)', 10);
	} 
	else{ 
		img.style.visibility = 'visible';
	} 
}

function mosaic_view_slider_resize(size) { 
	var num=1;
		
	while (num<=numOfAlbum) 
	{
		image = 'image'+num;
		$(image).width = size;

		num++;
	}
}

function mosaic_view_click_newimage()
{
	var filename = $('img').name;
	goToUrl("?image="+filename+"&album="+albumName+"&view=image&last=mosaic&color="+setColor);
}

/*////////////////////////////////
//                              //
//                              //
//         	skim 		  		//
//                              //
//                              //
////////////////////////////////*/

function skim_view_load(imageName)
{
	informations = $('information').value.split(";");
	albumCount = informations[2];
	$("bg").style.visibility = 'hidden';
	$('all').style.backgroundColor = 'rgb(0,0,0)';
	$("bg").style.margin = '0';
	$("all").style.visibility = 'visible';
	skim_view_resize();
}

function skim_view_resize()
{
	var local_winW = winW;
	var local_winH = winH;
	
	var scrollbar = glob_scrollbar;
	
	local_winW = local_winW-scrollbar;
	
	var minImgW = 150;
	
	var maxNum = local_winW/minImgW;
	
	maxNum = parseInt(maxNum); 
	
	var size = local_winW/maxNum;
	
	size = parseInt(size);
	
	var margintop	=0;
	var toptimes	=1;
	var times		=0;
	var num			=0;
	
	glob_time++;
	
	while (num<albumCount) 
	{
		albumHolder = $('albumHolder'+(num+1));
		
		if (times>=maxNum)
		{
			//margintop = (172*(toptimes))+(35*(toptimes+1));
			margintop = (235*(toptimes));
			//alert(toptimes+':'+margintop);
			times=0;
			toptimes++;
		}
		//alert('albumCount:'+albumCount+' times:'+times+ ' num:'+num+' maxNum:'+maxNum);
		albumHolder.style.left = (155*(times))+(17*(times+1))+'px';
		albumHolder.style.top = margintop+60+'px';
		times++;
		num++;
	}
}

/*////////////////////////////////
//                              //
//                              //
//         	other 		  		//
//                              //
//                              //
////////////////////////////////*/

function clickedOutsideElement(elemId,e) {
	e = e || window.event;
	var theElem = getEventTarget(e);
	
	while(theElem !== null) {
		if(theElem.id == elemId)
		{
			return false;
		}
		
		theElem = theElem.offsetParent;
	}
	return true;
}

function colorChange(action, color)
{
	pickerElem = $('color'+color);
	whiteElem = $('colorWhite');
	greyltElem = $('colorltGrey');
	greydkElem = $('colordkGrey');
	blackElem = $('colorBlack');
	bottomElem = $('bottom');
	topElem = $('top');
	if(action=='click')
	{
		setColor = color;
		if (urlView == 'grid')
		{
			elem = $('imagesgrid');
		}
		else
		{
			elem = $('imagesmos');
			elemB = $('oneimage');
			elemC = $('mosaic_photo_text');
		}
		classerName = pickerElem.className;
		classerName = classerName.replace("Select", '');
		classerName = classerName.replace("Hover", '');
		pickerElem.className = classerName+'Select';
		if(color=='White')
		{
			if (urlView == 'grid')
			{
				elem.style.backgroundColor = 'white';
			}
			else
			{
				elem.style.backgroundColor = 'white';
				elemB.style.backgroundColor = 'white';
				elemC.style.color = 'rgb(0,0,0)';
			}
			bottomElem.style.borderTopColor = 'rgb(0,0,0)';
			topElem.style.borderBottomColor = 'rgb(0,0,0)';
			greyltElem.className = 'colorltGrey';
			greydkElem.className = 'colordkGrey';
			blackElem.className = 'colorBlack';
		}
		if(color=='ltGrey')
		{
			if (urlView == 'grid')
			{
				elem.style.backgroundColor = 'rgb(150, 150, 150)';
			}
			else
			{
				elem.style.backgroundColor = 'rgb(150, 150, 150)';
				elemB.style.backgroundColor = 'rgb(150, 150, 150)';
				elemC.style.color = 'rgb(0,0,0)';
			}
			bottomElem.style.borderTopColor = 'rgb(0,0,0)';
			topElem.style.borderBottomColor = 'rgb(0,0,0)';
			whiteElem.className = 'colorWhite';
			greydkElem.className = 'colordkGrey';
			blackElem.className = 'colorBlack';
		}
		if(color=='dkGrey')
		{
			if (urlView == 'grid')
			{
				elem.style.backgroundColor = 'rgb(50, 50, 50)';
			}
			else
			{
				elem.style.backgroundColor = 'rgb(50, 50, 50)';
				elemB.style.backgroundColor = 'rgb(50, 50, 50)';
				elemC.style.color = 'rgb(150,150,150)';
			}
			bottomElem.style.borderTopColor = 'rgb(150,150,150)';
			topElem.style.borderBottomColor = 'rgb(150,150,150)';
			greyltElem.className = 'colorltGrey';
			whiteElem.className = 'colorWhite';
			blackElem.className = 'colorBlack';
		}
		if(color=='Black')
		{
			elem.style.backgroundColor = 'rgb(0, 0, 0)';
			if (urlView == 'grid')
			{
				elem.style.backgroundColor = 'rgb(0, 0, 0)';
			}
			else
			{
				elem.style.backgroundColor = 'rgb(0, 0, 0)';
				elemB.style.backgroundColor = 'rgb(0, 0, 0)';
				elemC.style.color = 'rgb(150,150,150)';
			}
			bottomElem.style.borderTopColor = 'rgb(150,150,150)';
			topElem.style.borderBottomColor = 'rgb(150,150,150)';
			greyltElem.className = 'colorltGrey';
			greydkElem.className = 'colordkGrey';
			whiteElem.className = 'colorWhite';
		}
	}
}

window.onresize = function()
{
	if (loaded==true)
	{
		window_handler("resize");
	}
}

window.onload = function()
{
	window_handler("load");
}

function gray_image_reflect_load(img)
{
	if(!img.complete)
	{
		var func = function() {gray_image_reflect_load(img);};
		imgWait=setTimeout(func, 10);
	} 
	else{ 
		album_view_load();
	} 
}

function window_handler(action)
{
	anaction = action;
	urlName = getFileName();
	urlView = getURLParam('view');
	albumName = getURLParam('album');
	if(typeof(window.innerWidth) === 'number' ) 
	{
		//Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
	{
		//IE 4 compatible
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
	if (anaction=='load')
	{
		glob_scrollbar = getScrollBarWidth();
		
		new Ajax.Request("ajaxinfo/input_start_info.php?album="+getURLParam('album')+"&image="+getURLParam('image')+"&view="+getURLParam('view')+"&last="+getURLParam('last')+"&color="+getURLParam('color'), {
            method: "post",onSuccess: function(transport) {
				respText = transport.responseText;
				$('information').value = respText;
			},asynchronous:false
		});
		
		informations = $('information').value.split(";");
		numOfAlbum = informations[0];
		startImage = informations[1];
		numberofalbums = informations[2];
		nowimage = informations[3];
		if (urlView=='mosaic')
		{
			new Ajax.Request("includes/album.php?album="+getURLParam('album')+"&image="+getURLParam('image')+"&view="+getURLParam('view')+"&last="+getURLParam('last')+"&color="+getURLParam('color'), {
           		method: "post",onSuccess: function(transport) {
					respText = transport.responseText;
					$('ajax_here').innerHTML = "";
					$('ajax_here').innerHTML = respText;
					$('view').style.visibility = 'visible';
					album_view_load();
				},asynchronous:false
			});
			Event.observe(document.body, 'click', function(event) {
				if (noClick=='')
				{
					var element = Event.element(event);
					var num=1;
					if (element.id == 'img')
					{
						mosaic_view_click_newimage(element);	
					}	
					while (num<=numOfAlbum) 
					{
						image = $('image'+num);
						if (image==element)
						{
							mosaic_view_add_new_image(image.id);	
						}
						num++;
					}
				}
			});
			noClick = '';
		}
		else if (urlView=='grid')
		{
			new Ajax.Request("includes/album.php?album="+getURLParam('album')+"&image="+getURLParam('image')+"&view="+getURLParam('view')+"&last="+getURLParam('last')+"&color="+getURLParam('color'), {
           		method: "post",onSuccess: function(transport) {
					respText = transport.responseText;
					$('ajax_here').innerHTML = "";
					$('ajax_here').innerHTML = respText;
					$('view').style.visibility = 'visible';
					var preload = new Image();
					preload.src = "images/gray500.gif";
					gray_image_reflect_load(preload);
				},asynchronous:false
			});
		}
		else if (urlView=='image')
		{
			new Ajax.Request("includes/image.php?album="+getURLParam('album')+"&image="+getURLParam('image')+"&view="+getURLParam('view')+"&last="+getURLParam('last')+"&color="+getURLParam('color'), {
           		method: "post",onSuccess: function(transport) {
					respText = transport.responseText;
					respText = respText.replace(/:;URL;:/g, (window.location.href));
					$('ajax_here').innerHTML = "";
					$('ajax_here').innerHTML = respText;
					image_view_load(nowimage);
					image_view_resize(nowimage);
				},asynchronous:false
			});
		}
		else
		{
			new Ajax.Request("includes/skim.php?page="+getURLParam('page')+"&album="+getURLParam('album')+"&image="+getURLParam('image')+"&view="+getURLParam('view')+"&last="+getURLParam('last'), {
           		method: "post",onSuccess: function(transport) {
					respText = transport.responseText;
					$('ajax_here').innerHTML = "";
					$('ajax_here').innerHTML = respText;
					skim_view_load();
				},asynchronous:false
			});
		}
	}
	
	if (anaction=='resize')
	{
		if (urlView=='grid' || urlView=='mosaic')
		{
			album_view_resize('resize');
		}
		else if (urlView=='image')
		{
			image_view_resize(nowimage);
		}
		else
		{
			skim_view_resize();
		}
	}
	loaded==true;
}