window.onload = function () {
	Indagare.nav.init();
	Indagare.controls.init();
}
Ajax.Responders.register({
  onCreate: function() {
    if($('indicator') && Ajax.activeRequestCount>0)
      $('indicator').show();
  },
  onComplete: function() {
    if($('indicator') && Ajax.activeRequestCount==0)
      $('indicator').hide();
  }
});
var Indagare = {
	panes: {
		current_pane: 1,
		show: function(holder,num) {
			// Indagare.pager.fix();
			this.getVisible(holder).each(function(el) { Indagare.panes.fade(el,'front');});
			this.appear(this.get(holder,num),'end');
			this.current_pane = num;
		},
		fade: function(el,q) {
			new Effect.Fade($(el),{duration:1,queue:{scope:'panes',position:q}});
		},
		appear: function(el,q) {
			new Effect.Appear($(el),{duration:1,queue:{scope:'panes',position:q}});
		},
		getVisible: function(holder) {
			var num = 1;
			var visible = [];
			while (this.get(holder,num) != undefined) {
				if (this.get(holder,num).visible()) 
					visible.push(this.get(holder,num));
				num++;
			}
			return visible;
		},
		get: function(holder,num) {
			return $(holder + '_' + num);
		},
		page: function(holder,pager) {
			var page_id = $(pager).id.replace(/pager_/,'');
			// alert(page_id);
			if (page_id == 'next') {
				var next_pane = parseInt(this.current_pane) + 1;
				if (this.get(holder,next_pane)) {
					page_id = next_pane;
				} else {
					page_id = 1;
				}
				pager = $('pager_'+page_id);
			} else if (page_id == 'back') {
				var prev_pane = parseInt(this.current_pane) - 1;
				if (prev_pane == 0) {
					page_id = 1;
				} else {
					page_id = prev_pane;
				}
				pager = $('pager_'+page_id);
			} 
			this.show(holder,page_id);
			Indagare.pager.outin();
			Indagare.pager.makeSelected(pager);
		}
	},
	pager: {
		get: function() {
			return $('pager');
		},
		outin:function() {
			new Effect.Fade(this.get(),{duration:1,queue:{position:'front',scope:'pager'}});
			new Effect.Appear(this.get(),{duration:1,queue:{position:'end',scope:'pager'}});
		},
		fix: function() {
			return this.get().makePositioned();
		},
		getLinks: function() {
			return $$('#pager>ul>li>a');
		},
		makeSelected: function(pager_el) {
			this.makeAllUnselected();
			Element.addClassName($(pager_el),'selected');
		},
		makeAllUnselected: function() {
			this.getLinks().each(function (el,i) {
				Element.removeClassName($(el),'selected');
			});
		}
	},
	popup: function(link,title,width,height) {
		window.open(link,title,"height="+height+",width="+width+",status=no,toolbar=no,menubar=no,location=no");
	},
	fonts: {
		sizes: ['normal','medium','large'],
		css_prefix: 'font_size_',
		setSize: function(size, clicker) {
			Indagare.appRequest('/home/set_font_size',{size: size});
			this.sizes.each(function(asize) {
				if ($('container').hasClassName(this.css_prefix + asize)) {
					$('container').removeClassName(this.css_prefix + asize)
				}
			}.bind(this));
			$('container').addClassName(this.css_prefix + size)
			clicker.up().up().select('span a').each(function(link) {
				link.removeClassName('selected');
			})
			clicker.addClassName('selected');
		}
	},
	departments: {
		updateSort: function (sortable_id) {
			var section_id = $(sortable_id).id.replace(/departments_/,'');
			var url = '/departments/update_sort/' + section_id;
			Indagare.updateSort(sortable_id, url);
		},
		dropdown: function(section_id,obj) {
			var params = "id=" + section_id;
				if (obj && obj != '') {
					params += "&obj="+obj;
				}

			new Ajax.Request(
					'/departments/dropdown',
					{
						method: 'post',
						parameters: params
					});
		}
	},
	destinations: {
		dropdown: function (area_type, search, obj, show_name) {
			var params = "area_type="+area_type+"&search="+search;
			if (obj && obj != '') {
				params += "&obj="+obj;
			}
			if (show_name && show_name != '') {
				params += "&show_name=1";
			}
			new Ajax.Request(
					'/destinations/dropdown',
					{
						method: 'post',
						parameters: params
					});
		}
	},
	favorites: {
		init: function() {
/*			"add_to_itinerary_select_"*/
			$$('.add_to_itinerary_select').each(function(el,i) {
				el.onchange = function () {
					if (this.value == '!') {
						Indagare.favorites.itineraryPrompt(this.id.replace(/add_to_itinerary_select_/,''));
					}
				}
			});
			$$('.add_to_itinerary_form>form').each(function(el,i) {
				el.onsubmit = function () {
					itin_select = el.getElements().first();
/*					alert(itin_select);*/
					if (itin_select.value == '!') {
						Indagare.favorites.itineraryPrompt(itin_select.id.replace(/add_to_itinerary_select_/,''));
						return false;
					} else {
						return true;
					}
				}
			}); 
		},
		addToSwap: function(id) {
			$('add_to_itinerary_link_'+id).toggle();
			$('add_to_itinerary_form_'+id).toggle();
		},
		itineraryPrompt: function(from_favorite) {
			var newitem = false;
			var default_message = "Enter the name of the new Itinerary:";//+from_favorite;
			//while (!newcontext) {
			newitem = prompt(default_message,'');
			var loading = function (oR) {
				Field.disable('add_to_itinerary_select_'+from_favorite);
			};
			var complete = function (oR) {
				Field.enable('add_to_itinerary_select_'+from_favorite);
			}; 
			if (newitem) {
				new Ajax.Request(
						'/my_travel/itineraries/new',
						{
							method: 'post',
							evalScripts:true,
							onLoading: loading,
							onComplete: complete,
							parameters: "itinerary[title]="+newitem+"&from_favorite="+from_favorite
						});
			} else {
				newitem = false;
			}
		}
	},
	itinerary: {
		sorting: false,
		itinerary_id: 0,
		toggleSort: function(el_id) {
			var itin = $(el_id);
			this.itinerary_id = itin.id.replace(/itinerary_/,'');
			if (this.sorting) {
				Sortable.destroy('itinerary_items_table');
				itin.toggleClass('sorting');
				this.sorting = false;
			} else {
				itin.toggleClass('sorting');
				this.createSortable('itinerary_items_table');
				this.sorting = true;
			}
		},
		toggleDragging: function(el) {
			el.toggleClass('dragging');
			return false;
		},
		createSortable: function(el) {
/*			alert(this.itinerary_id);*/
			var sendupdate = function(sortable) { this.update(sortable,this.itinerary_id); }.bind(this);
			return Sortable.create(el,{tag: 'tr',onUpdate:sendupdate,starteffect:Indagare.itinerary.toggleDragging,endeffect:Indagare.itinerary.toggleDragging});
		},
		startdrag: function(el) {
/*			el.addClassName('dragging')*/
		},
		update: function(sortable_id,itin_id) {
/*			alert(this.itinerary_id);*/
			Indagare.appRequest('/my_travel/itineraries/sort/'+itin_id,Sortable.serialize(sortable_id));
		}
	},
	//
	// NAV ELEMENTS
	//
	nav: {
		main_prefix: "main_nav_",
		sub_prefix:"sub_nav_",
		init: function () {
			var controller = Indagare.nav;
			$$('#nav>ul>li').each(function(el,index) {
				el.onmouseover = function () {
					controller.openSubnav(el);
				};
/*				el.onmouseout = function () {
					controller.closeSubnav(el);
				} */
			$('content').onmouseover = function () {
				controller.closeAllSubs();
			}
		});
		},
		openSubnav: function(elem) {
			this.closeAllSubs();
			var sub_nav = this.getSubnav(elem);
			if (sub_nav) { 
				sub_nav.show();
/*				new Effect.BlindDown(sub_nav, {	duration: 0.2	}); */
			}
		},
		closeSubnav: function(elem) {
			var sub_nav = this.getSubnav(elem);
			if (sub_nav) { sub_nav.hide(); }
		},
		getSubnav: function(elem) {
			var sub_id = $(elem).id.replace(this.main_prefix, this.sub_prefix);
			return $(sub_id);
		},
		closeAllSubs: function() {
/*			$$('#nav>ul>li').getElementsBySelector('ul')*/
			$$('#nav ul>li>ul').each(this.closeSubnav.bind(this));
		}
	},
	controls: {
		active: true,
		init: function() {	
			$$('.article_controls span').each(function(el,index) {
					//preload
					if (el == undefined || !Indagare.controls.tooltip(el)) { return false; }
					MM_preloadImages(Indagare.images.deactivateSrc(Indagare.controls.img(el)),Indagare.images.hoverSrc(Indagare.controls.img(el)),'/images/icon_toolbar_arrow.gif');
					el.onmouseover = function () { Indagare.controls.hover(this); };
					el.onmouseout = function () { Indagare.controls.hoverout(this); };
/*					Indagare.controls.hoverout(el);*/
				});
				$$('img.quick_control').each(function(el,index) {
						//preload
						if (el == undefined) { return false; }
						MM_preloadImages(Indagare.images.deactivateSrc(el),Indagare.images.hoverSrc(el));
						el.onmouseover = function () { Indagare.images.hover(this); };
						el.onmouseout = function () { Indagare.images.deactivate(this); };
					});
		},
		hover: function(el) {
			if (this.active) {
				Indagare.images.hover(this.img(el));
/*			Effect.Appear(Indagare.controls.tooltip(el), {duration: 0.1, fps: 30});*/
				Indagare.controls.tooltip(el).show();
			}
		},
		hoverout: function(el) {
			Indagare.images.deactivate(this.img(el));
			Indagare.controls.tooltip(el).hide();
		},
		img: function(el) {
			return $($(el).id + '_img');
		},
		tooltip: function(el) {
			var tooltip_id = $(el).id + "_tooltip";
			return $(tooltip_id);
		}
	},
	sendToMobile: {
		open: function(article_id) {
			Indagare.appRequest('/articles/send_to_mobile/'+article_id,'','get');
			new Effect.BlindDown(this.holder(article_id),{fps:30,duration:.5,direction:'bottom-right',scaleX:false});
			Indagare.controls.active = false;
		},
		close: function (article_id) {
			new Effect.BlindUp(this.holder(article_id),{fps:30,duration:.5,direction:'bottom-right',scaleX:false})
			Indagare.controls.active = true;
		},
		send: function (article_id) {
			var params = Form.serialize('send_to_mobile_form_'+article_id);
			Indagare.appRequest('/articles/send_to_mobile/'+article_id,params);
			var submit = $('send_to_mobile_submit_'+article_id);
			Field.disable(submit);
			submit.value = 'Sending . . .';
			return false;
		},
		holdThenClose: function(article_id) {
			setTimeout('Indagare.sendToMobile.close('+article_id+')', 1000);
		},
		holder: function (article_id) {
			return $('send_to_mobile_'+article_id);
		}
	},
	photoSelector: {
		current_search: false,
		current_page: 1,
		photo_link_holder_id: 'photos_to_link',
		attached_photos_id: 'attached_photos_thumbs',
		getSelectableThumbs: function (page, search, check) {
			var params = '';
			if (parseInt(page))  { params += 'page=' + parseInt(page) + '&'; }
			if (search)  { params += 'search=' + search + '&'; }
			if (check) { params += 'check=1&'; }
			new Ajax.Request(
					'/admin/photos/photo_selector',
					{
						method: 'post',
						evalScripts:true,
						parameters: params
					});
		},
		nextPage: function () {
			this.current_page++;
			return this.refreshThumbs(false);
		},
		previousPage: function () {
			this.current_page--;
			return this.refreshThumbs(false);
		},
		search: function(field_that_holds_query) {
			this.current_search = $(field_that_holds_query).value;
			return this.refreshThumbs(false);
		},
		refreshThumbs: function (check) {
			return this.getSelectableThumbs(this.current_page,this.current_search,check);
		},
		resetSearch: function() {
			this.current_search = false;
			this.current_page 	= 1;
			return this.refreshThumbs(false);
		},
		addToAttached: function (photo_id, photo_url, caption) {
      $(this.attached_photos_id).insert({bottom: this.attachedThumbHTML(photo_id,photo_url,caption)});
			var current_photo_links = $(this.photo_link_holder_id).value;
			$(this.photo_link_holder_id).value = current_photo_links + photo_id + ",";
		},
		removeAttached: function (id) {
			new Effect.Fade('attached_photo_'+id, {onFinish: Element.Remove });
			var current_photo_links = $(this.photo_link_holder_id).value;
			$(this.photo_link_holder_id).value = current_photo_links.replace(id+",", '');
		},
		attachedThumbHTML: function(pid,url,caption) {
			var attached_html = '<li id="attached_photo_'+ pid + '" class="thumb" onmouseover="$(\'attached_photo_'+pid+'_controls\').show();" onmouseout="$(\'attached_photo_'+pid+'_controls\').hide();">';
			attached_html += '<img src="'+url+'" />';
			attached_html +=	'<div class="thumb_controls" id="attached_photo_'+pid+'_controls" style="display:none;"><p><em>'+caption+'</em></p><p><a href="#" onclick="Indagare.photoSelector.removeAttached('+pid+'); return false;">x Remove</a></p></li>';
			return attached_html;
		},
		miniUpload: {
			uploader_id: 'mini_upload',
			open: function () {
				$(this.uploader_id).show();
			},
			close: function () {
				$(this.uploader_id).hide();
				Indagare.photoSelector.getSelectableThumbs(true);
			}
		}
	},
	giftOption: {
		fields: ['name','email','message','address'],
		showFields: function (mlid, ship_type) {
/*			alert(this.fields);*/
			this.fields.each(function(v) {
				Indagare.giftOption.getField(mlid,v).hide();
			});
			this.fieldsForType(ship_type).each(function(v) {
				Indagare.giftOption.getField(mlid,v).show();
			});
		},
		getField: function(mlid,field) {
			return $('membership_line_item_'+mlid+'_form_'+field);
		},
		fieldsForType: function(ship_type) {
			switch(ship_type) {
				case "physical":
					return ['name','message','address'];
				break;
				case "electronic":
					return ['name','email','message'];
				break;
				case "to_me":
					return [];
				break;
			}
		}
	},
	lightbox: {
		lbox: "",
		slides : [],
		get: function(article_id, clicked_element) {
			Indagare.appRequest('/articles/lightbox/'+article_id, {});
/*			var slides = #{images_as_json(@photos)};*/
		},
		load: function () {
			this.lbox = new Lightbox('lightbox',this.slides, this.getOffset());
/*			Indagare.scrollTo('lightbox');*/
			// set the carousel with
			this.carousel.setWidth();
		},
		carousel: {
			carousel_id: 'lb_thumbs_carousel',
			page_size: 98,
			current_x: 0,
			at_slide: 0,
			animating: false,
			next: function () {
				if (this.at_slide + 2 >= this.length()) return;
				var difference = (this.page_size);
				this.current_x -= difference;
				this.moveHorizontal(this.current_x);
				this.at_slide++;
			},
			previous: function () {
				if (this.at_slide <= 0) return;
				var difference = (this.page_size);
				this.current_x += difference;
				this.moveHorizontal(this.current_x);
				this.at_slide--;
			},
			moveHorizontal: function (pixels) {
				if (this.animating) return;
				this.animating = true;
				$(this.carousel_id).morph('left:'+pixels+'px', {duration: 0.5, 
					afterFinish: function(e) {
						this.animating = false;
						e.style.left = pixels + 'px';
					}.bind(this) 
				});
			},
			setWidth: function() {
				var width = this.page_size * this.length();
				if (this.length() < 2) width += this.page_size;
				$(this.carousel_id).style.width = width + 'px';
				$(this.carousel_id).style['z-index'] = 0;
			},
			length: function() {
				return Indagare.lightbox.slides.length;
			}
		},
		getOffset: function() {
			var scroll_top = document.viewport.getScrollOffsets()['top'];
			return scroll_top;
		}
	},
	appRequest: function(url,params, method) {
		if (!method) {method = 'post';}
		return new Ajax.Request(url,{ method: method,	evalScripts:true, parameters: params });
	},
	updateSort: function(sortable_id,url) {
		new Ajax.Request(
				url,
				{
					method: 'post',
					evalScripts:true, 
					parameters: Sortable.serialize(sortable_id)
				});
	},
	scrollTo: function(el) {
		new Effect.ScrollTo(el, {duration: 0.5, fps: 30});
	},
	images: {
		swap: function(for_el,to) {
			$(for_el).src = to;
		},
		activate: function (for_el) {
			return this.swap(for_el,this.activateSrc(for_el));
		},
		deactivate: function (for_el) {
			return this.swap(for_el,this.deactivateSrc(for_el));		
		},
		hover: function (for_el) {
			return this.swap(for_el,this.hoverSrc(for_el));
		},
		replaceSrc: function (for_el,search,replace_with) {
			return $(for_el).src.replace(search,replace_with);
		},
		activateSrc: function (for_el) {
			return this.replaceSrc(for_el,/_off/,'_on');
		},
		deactivateSrc: function (for_el) {
			return this.replaceSrc(for_el,/_on/,'_off');
		},
		hoverSrc: function (for_el) {
			return this.replaceSrc(for_el,/_off/,'_on');
		},
		restore: function (for_el) {
			MM_swapImgRestore();
		}
	}
};

var Slideshow = Class.create();
Slideshow.prototype = {
		current: 0,
		caption_id: "hero_slide_caption",
		image_id: "hero_slide_image",
		pager: "slide_pager",
		pager_prefix: "hero_slide_pager_",
		paused: false,
		cycle_time:12,
		close_time: .5,
		open_time: 1,
		initialize: function(slides) {
			this.slides = slides;
			this.preloadSlides(slides);
		},
		preloadSlides: function(slides) {
			$A(slides).each(function (el,index) {
				MM_preloadImages(el.public_url);
			});
		},
		startup: function() { 
			new PeriodicalExecuter(function(pe) {
				if (this.paused) {
					pe.stop();
				} else {
					this.go();
				}
			}.bind(this), this.cycle_time); // change image every 5 seconds
		},
		current_slide: function() {
			return this.slides[this.current];
		},
		prev_id: function() {
			var prev = this.current-1;
			if (prev < 0) {
				prev = this.slides.length-1;
			}
			return prev;
		},
		next_id: function() {
			var next = this.current+1;
			if (next > this.slides.length-1) {
				next = 0;
			}
/*			alert(next);*/
			return next;
		},
		next: function () {
			this.go();
		},
		prev: function () {
			this.current = this.prev_id();
			this.goToCurrent();
		},
		go: function(slide_id, witheffect) {
			if (slide_id != undefined) {
				this.current = slide_id;
			} else {
				this.current = this.next_id();
			}
			this.goToCurrent(witheffect);
		},
		cycle: function(htid, newcontent, witheffect) { 
			if (witheffect != undefined && witheffect == false) {
					$(htid).update(newcontent);
			} else {
			this.closeEffect(htid, { 
								duration: this.close_time, 
								fps: 24,
								afterFinish: function() {
										$(htid).update(newcontent);
										this.openEffect(htid, { duration: this.open_time,	fps: 24, queue:'end'}); 
								}.bind(this)
			});
			}
		},
		pause: function(pause_for) {
			this.paused = true;
		},
		goToCurrent: function(witheffect) {
			//cycle image
			this.cycle(this.image_id,this.image_html(this.current_slide()),witheffect);
			//cycle caption_id
			this.cycle(this.caption_id,this.caption_html(this.current_slide()),witheffect);
			this.selectCurrentPager();
		},
		selectCurrentPager: function () {
			$$("#"+this.pager+" li").each(function(el,i) {
					el.removeClassName('selected');
			});
			$(this.pager_prefix + this.current).addClassName('selected');
		},
		caption_html: function(slide) {
			var html = "<p>"+slide.caption
			if (slide.url != "") {
				html += "&nbsp;<a href=\""+slide.url+"\">More Info</a></p>";
			}
			return html;
		},
		image_html: function(slide) {
			var html = "";
			if (slide.url != "") { html += "<a href=\""+slide.url+"\">";	}
			html += "<img src=\""+slide.public_url+"\" alt=\""+slide.title+"\" />";
			if (slide.url != "") { html += "</a>"; }
			return html;
		},
		openEffect: Effect.Appear,
		closeEffect: Effect.Fade
}; 

var Lightbox = Class.create();
Lightbox.prototype = Object.extend(new Slideshow,{
	overlay: 'overlay',
	lb_element: 'lightbox',
	caption_id: "lb_current_caption",
	image_id:	"lb_current_image",
	close_button_id: "lb_close",
	caption_property: "caption",
	cycle_time: 12,
	top_offset: 50,
	initialize: function(lbel,slides, top_offset) {
		this.lb_element = lbel;
		this.slides 		= slides;
		if (top_offset != undefined) this.top_offset = this.top_offset + top_offset;
		this.preloadSlides(slides);
	},
	open: function() {
		this.expandOverlay();
		$(this.lb_element).style.top = this.top_offset + "px";
		$(this.overlay).show();
		$(this.close_button_id).show();
		this.openEffect(this.lb_element);
		this.hideFlash()
	},
	close: function() {
		$(this.close_button_id).hide();
		this.closeEffect(this.lb_element, {fps: 30, duration: 0.2});
		setTimeout(function() {this.closeEffect(this.overlay, {fps: 30, duration: 0.2}); }.bind(this),200);
		this.pause();
		this.showFlash()
		this.current = 0;
	},
	selectCurrentPager: function () {},
	caption_html: function(slide) {
		return "<p>"+slide[this.caption_property]+"</p>";
	},
	image_html: function(slide) {
		return "<img src=\""+slide.public_url+"\" alt=\""+slide[this.caption_property]+"\" />";
	},
	expandOverlay: function () {
		var arrayPageSize = getPageSize();
		$(this.overlay).setHeight(arrayPageSize[1]);
	},
	hideFlash: function () {
		$$('.flash_container').each(Element.hide);
	},
	showFlash: function() {
		$$('.flash_container').each(Element.show);
	},
	openEffect: Effect.Appear,
	closeEffect: Effect.Fade
});






Element.addMethods({
	toggleClass: function(elem,css) { 
		if (Element.hasClassName(elem,css)) {
			Element.removeClassName(elem,css);
		} else {
			Element.addClassName(elem,css);
		}
	},
	setHeight: function(elem,h) {
   		elem = $(elem);
    	elem.style.height = h +"px";
	},
	setZ: function (elem,z) {
		$(elem).style.zIndex = z;
	},
	appendValue: function(elem,s) {
		var current = $(elem).value;
		$(elem).value = current + s;
	},
	removeValue: function(elem, s) {
		var current = $(elem).value;
		$(elem).value = current.replace(s,'');
	}
	
});

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
