var previous = 0;
var previous_qc = 0;
var previous_flickr = 0;

$(function() {
	$('a.lightbox').lightBox({fixedNavigation:true});
	layer();
});

function layer(){
	$("a#hidden").fancybox({'type':'inline'}).trigger('click');
}

function loadFlickr(user_id, key){
	//var user_id = "51878904@N07";
	//var key = "1aa6bc9070b53538f4537ca74ea6fcb8";
	var furl = "http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key="+key+"&user_id="+user_id+"&per_page=15&extras=original_format&format=json&jsoncallback=?";

	$.ajax({url: furl,
		cache: false,
		dataType: "json",
		success: function(data){
			var str = '';
			var x = 1;
			$.each(data.photos.photo, function(i,item){
		        var photo = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_s.jpg';
				var link = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_b.jpg';
				
				str += '<div id="image">';
					str += '<a href="'+link+'" class="lightbox"><img src="'+photo+'" border="0" width="50" height="50"></a>';
				str += '</div>';
				x++;
			});
			$("#load_flickr").html(str);

			$('a.lightbox').lightBox({fixedNavigation:true});
		}
	});
}

function loadBlog(lang, id, object){
	$.ajax({
		url: "/ajax.php?action=blog&lang="+lang+'&id='+id, cache: true, success: function(html){
			$(object).html(html);
		}
	});
}

function initQC(aantal, width, perpage){
	checkQC(aantal, perpage);
	$("a#pag_"+previous_qc).addClass("active");
	$("div#qc_btn_right").click(function(){
		moveQC(aantal, previous_qc+1, width, perpage);
	});
	$("div#qc_btn_left").click(function(){
		moveQC(aantal, previous_qc-1, width, perpage);
	});
}

function checkQC(aantal, perpage){
	if (aantal>perpage && ((previous_qc+1)*perpage)<=aantal){
		$("div#qc_btn_right").show();
	} else {
		$("div#qc_btn_right").hide();
	}
	if (previous_qc>0){
		$("div#qc_btn_left").show();
	} else {
		$("div#qc_btn_left").hide();
	}
}

function moveQC(aantal, nr, width, perpage){
	$("div#qc_content").animate({ "marginLeft": '-'+((nr)*width)+'px' }, 300);
	$("a#pag_"+previous_qc).removeClass("active");
	$("a#pag_"+nr).addClass("active");
	previous_qc = nr;
	checkQC(aantal, perpage);
}

function loadYoutube(data){
	loadYoutubeData(data, '#load_youtube');
}

function loadYoutubeQC(data){
	loadYoutubeData(data, '#quinnycaster_youtube_content');
}

function loadYoutubeData(data, object){
	var feed = data.feed;
	var entries = feed.entry || [];

	for (var i = 0; i < entries.length; i++) {
		var entry = entries[i];
		var title = entry.title.$t.substr(0, 20);

		var name = entry.author[0].name.$t;

		var thumbnailUrl = entries[i].media$group.media$thumbnail[3].url;
		var playerUrl = entries[i].media$group.media$content[0].url;

		var count = entry.yt$statistics.viewCount;

		var yt_html = '<div id="video">';
			yt_html += '<div id="thumb"><a href=\"javascript:showMovie(\'700\',\'430\',\''+playerUrl+'\');\"><img src="'+thumbnailUrl+'" border="0"></a></div>';
			yt_html += '<div id="tekst">';
				yt_html += '<div class="titel">'+title+'</div>';
				yt_html += '<div class="name">Uploaded by: '+name+'</div>';
				yt_html += '<div class="count">'+count+' views</div>';
				yt_html += '<div class="hlijn"></div>';
			yt_html += '</div>';
		yt_html += '</div>';
		
		$(object).append(yt_html);
	}
}

function loadFlickrSet(set_id){
	var key = "1aa6bc9070b53538f4537ca74ea6fcb8";
	var furl = "http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key="+key+"&photoset_id="+set_id+"&extras=original_format&format=json&jsoncallback=?";

	$.ajax({url: furl,
		cache: false,
		dataType: "json",
		success: function(data){
			var str = '<div id="quinnycaster_flickr_photo">';
			var x = 1;
			$.each(data.photoset.photo, function(i,item){
		        var photo = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_s.jpg';
				var link = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_b.jpg';
				
				str += '<div>';
					str += '<a href="'+link+'" class="lightbox"><img src="'+photo+'" border="0" width="60" height="60"></a>';
				str += '</div>';
				if ((x % 2)==0){
					if ((x % 10) == 8){
						str += '</div><div id="quinnycaster_flickr_photo_next">';
					} else {
						str += '</div><div id="quinnycaster_flickr_photo">';
					}
				} else {
					str += '<div style="height: 10px;"></div>';
				}
				x++;
			});
			$("div#quinnycaster_flickr_photos").html(str);

			$('a.lightbox').lightBox({fixedNavigation:true});

			$("div#quinnycaster_flickr_btn_left").click(function(){
				slideFlickrSet(previous_flickr-1, x);
			});

			$("div#quinnycaster_flickr_btn_right").click(function(){
				slideFlickrSet(previous_flickr+1, x);
			});
		}
	});
}

function slideFlickrSet(nr, aantal){
	if ((nr>=0) && ((aantal/9)>nr)){
		$("div#quinnycaster_flickr_scroller-content").animate({ "marginLeft": '-'+(nr*414)+'px' }, 300);
		previous_flickr = nr;
	}
}

function loadFlickrFase2(user_id, key){
	//var user_id = "51878904@N07";
	//var key = "1aa6bc9070b53538f4537ca74ea6fcb8";
	var furl = "http://api.flickr.com/services/rest/?method=flickr.urls.lookupGallery&api_key="+key+"&url=http://www.flickr.com/photos/quinnycasters/galleries/"+user_id+"&extras=original_format&format=json&jsoncallback=?";
	$.ajax({url: furl,
		cache: false,
		dataType: "json",
		success: function(data){
			var gallery_id = data.gallery.id;
			var furl = "http://api.flickr.com/services/rest/?method=flickr.galleries.getPhotos&api_key="+key+"&gallery_id="+gallery_id+"&extras=original_format&format=json&jsoncallback=?";
			$.ajax({url: furl,
				cache: false,
				dataType: "json",
				success: function(data){
					var str = '';
					var x = 0;
					$.each(data.photos.photo, function(i,item){
						var photo = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_s.jpg';
						var link = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_b.jpg';
						
						str += '<div id="image">';
							str += '<a href="'+link+'" class="lightbox"><img src="'+photo+'" border="0" width="60" height="60"></a>';
						str += '</div>';
						x++;
					});
					$("#home_flickr").html(str);

					$('a.lightbox').lightBox({fixedNavigation:true});

					$("table#flickr td.left img").click(function(){
						slide(previous-1, x);
					});

					$("table#flickr td.right img").click(function(){
						slide(previous+1, x);
					});
				}
			});

		}
	});	
}

/* PHP Variant
function loadFlickr(){
   	// Load Flickr (more info)
	$.ajax({
		url: "/ajax.php?action=flickr", cache: true, success: function(html){
			$("#load_flickr").html(html);
			$('a.lightbox').lightBox({fixedNavigation:true});
		}
	});
} */

// PHP VERSION
/*function loadFlickrSet(set_id){
	// Load Flickr (more info)
	$.ajax({		
		url: "/ajax.php?action=flickrset&set_id="+set_id, 
		cache: true, 
		dataType: "xml",
		success: function(xml){
			$(xml).find('item').each(function(){
				var aantal = $(this).attr("aantal");
				var html = $(this).text();
				$("div#quinnycaster_flickr_photos").html(html);
				$('a.lightbox').lightBox({fixedNavigation:true});

				$("div#quinnycaster_flickr_btn_left").click(function(){
					slideFlickrSet(previous_flickr-1, aantal);
				});

				$("div#quinnycaster_flickr_btn_right").click(function(){
					slideFlickrSet(previous_flickr+1, aantal);
				});
			});
		}
	});
}*/

/* PHP Variant
function loadFlickrFase2(){
	// Load Flickr (more info)
	$.ajax({
		url: "/ajax.php?action=flickr2", 
		cache: true, 
		dataType: "xml",
		success: function(xml){

			$(xml).find('item').each(function(){
				var aantal = $(this).attr("aantal");
				var html = $(this).text();
				$("#home_flickr").html(html);
				$('a.lightbox').lightBox({fixedNavigation:true});

				$("table#flickr td.left img").click(function(){
					slide(previous-1, aantal);
				});

				$("table#flickr td.right img").click(function(){
					slide(previous+1, aantal);
				});
			});
		}
	}); 
}*/

function loadTwitter(lang, user, object){
	$.ajax({
		url: "/ajax.php?action=twitter&id="+user+"&lang="+lang, 
		cache: true, 
		dataType: "html",
		success: function(html){
			$(object).html(html);
			$(object).linkify();
		}
	});
}

/*function loadTwitter(user, hash, object, txt_hours, txt_notweets){

	// Declare variables to hold twitter API url and user name
    var twitter_api_url = 'http://search.twitter.com/search.json';
    var twitter_user = user;
	var twitter_hash = hash;
	var count = 4;

	var full_url = twitter_api_url + '?callback=?&rpp='+count+'&q=from:'+twitter_user;
	if (twitter_hash!=''){
		full_url += '+'+twitter_hash;
	}

    // Enable caching
    $.ajaxSetup({ cache: false });

    // Send JSON request
    // The returned JSON object will have a property called "results" where we find
    // a list of the tweets matching our request query
    $.getJSON(
        full_url,
        function(data) {
			var found = false;
			$(object).html('');
			if (data.results){
				$.each(data.results, function(i, tweet) {
					// Uncomment line below to show tweet data in Fire Bug console
					// Very helpful to find out what is available in the tweet objects
					//console.log(tweet);

					// Before we continue we check that we got data
					if(tweet.text !== undefined) {
						// Calculate how many hours ago was the tweet posted
						var date_tweet = new Date(tweet.created_at);
						var date_now   = new Date();
						var date_diff  = date_now - date_tweet;
						var hours      = Math.round(date_diff/(1000*60*60));

						// Build the html string for the current tweet
						var tweet_html = '<div id="tweet">';
							tweet_html += '<div id="tweet_left"></div>';
							tweet_html += '<div id="tweet_top"></div>';
							tweet_html += '<div id="tweet_back">';
								tweet_html += '<div class="tweet_text">';
								tweet_html += tweet.text + '<\/div>';
								tweet_html += '<div class="tweet_hours">';
								tweet_html += '<a href="http://www.twitter.com/';
								tweet_html += twitter_user + '/status/' + tweet.id + '">';
								tweet_html += hours;
								tweet_html += ' '+txt_hours+'';
								tweet_html += '<\/a>';
								tweet_html += '<\/div>';
							tweet_html += '</div>';
							tweet_html += '<div id="tweet_bottom"></div>';
						tweet_html += '</div>';

						// Append html string to tweet_container div
						$(object).append(tweet_html);

						$(object).linkify();
						found = true;
					}
				});
			}
			if (!found) {
				$(object).html('<div id="tweet"><div class="tweet_text">'+txt_notweets+'</div></div>');
			}
        }
    );
}*/

/// JQuery make links (target=_blank)
// Call andy jquery object $('#....').linkify();
(function($){ 
   var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g, 
      url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g, 
 
      linkifyThis = function () { 
        var childNodes = this.childNodes, 
            i = childNodes.length; 
        while(i--) 
        { 
          var n = childNodes[i]; 
          if (n.nodeType == 3) { 
            var html = $.trim(n.nodeValue); 
            if (html) 
            { 
              html = html.replace(/&/g, '&amp;') 
                         .replace(/</g, '&lt;') 
                         .replace(/>/g, '&gt;') 
                         .replace(url1, '$1<a href="http://$2" target="_blank">$2</a>$3') 
                         .replace(url2, '$1<a href="$2" target="_blank">$2</a>$5'); 
              $(n).after(html).remove(); 
            } 
          } 
          else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) { 
            linkifyThis.call(n); 
          } 
        } 
      }; 
 
  $.fn.linkify = function () { 
    return this.each(linkifyThis); 
  }; 
})(jQuery); 

function slide(nr, aantal){
	if ((nr>=0) && ((aantal/9)>nr)){
		$("#scroller-content").animate({ "marginLeft": '-'+(nr*795)+'px' }, 300);
		previous = nr;
	}
}

function showBox(msg, my){
	var myDiv = document.createElement('div');
	myDiv.setAttribute('id', 'message_box'); 
	myDiv.innerHTML = msg;
	my.appendChild(myDiv);
}

function removeBox(my){
	var kids = my.childNodes;
	for (j=0; j < kids.length; j++) {
		if (kids[j].id=='message_box'){
			my.removeChild(kids[j]);
		}
	}
}

function loadMovie(url){
	var ytplayer = document.getElementById("myytplayer");
	if (ytplayer) {
  		ytplayer.loadVideoByUrl(url,0);
	}
}

function changeItem(item, my){
	if (my.checked)	{
		document.getElementById(item).className = 'inputtext';
		document.getElementById(item).onclick = clearInput;
		document.getElementById(item).readOnly = false;
	} else {
		document.getElementById(item).className = 'inputtext_dis';
		document.getElementById(item).onclick = null;
		document.getElementById(item).readOnly = true;
	}
}

function clearInput(){
	this.value = '';
}

function changeImage(img){
	document.getElementById('collection').src = "/images/collection/"+img;		
}

function changePregnant(text, value){
	var tbody = document.getElementById("pregnant_date").getElementsByTagName("TBODY")[0];
	var element = document.getElementById("pregnant_date_input");		
	if (value){
		if (!element){		
			var row = document.createElement("TR");
			row.id = "pregnant_date_input";
			var td1 = document.createElement("TD");
			td1.className = "formitem";
			td1.style.width = '150px';
			td1.appendChild(document.createTextNode(text));
			var td2 = document.createElement("TD");
			
			var inputElementM = document.createElement("select");
			inputElementM.className = 'inputtext';
			inputElementM.id = 'pregnant_date_maand';
			inputElementM.name = 'pregnant_date_maand';
			inputElementM.style.width = '40px';
			for (i=1; i<=12; i++){
				var objOption = document.createElement("option");
				objOption.text=i;
				objOption.value=i;
				inputElementM.options.add(objOption);
			}

			var inputElementD = document.createElement("select");
			inputElementD.className = 'inputtext';
			inputElementD.id = 'pregnant_date_dag';
			inputElementD.name= 'pregnant_date_dag';
			inputElementD.style.width = '40px';
			for (i=1; i<=31; i++){
				var objOption = document.createElement("option");
				objOption.text=i;
				objOption.value=i;
				inputElementD.options.add(objOption);
			}

			var inputElementY = document.createElement("select");
			inputElementY.className = 'inputtext';
			inputElementY.id = 'pregnant_date_jaar';
			inputElementY.name = 'pregnant_date_jaar';
			inputElementY.style.width = '60px';

			var now = new Date();
			var year = now.getFullYear();
			for (i=year; i<=(year+1); i++){
				var objOption = document.createElement("option");
				objOption.text=i;
				objOption.value=i;
				inputElementY.options.add(objOption);
			}

			td2.appendChild(inputElementD);
			td2.appendChild(document.createTextNode(" "));
			td2.appendChild(inputElementM);
			td2.appendChild(document.createTextNode(" "));
			td2.appendChild(inputElementY);
			row.appendChild(td1);
			row.appendChild(td2);
			tbody.appendChild(row);
		}
	} else {
		if (element){
			tbody.removeChild(element);
		}
	}
}

function clearDateInput(){
	if (this.value=='yyyy' || this.value == 'mm' || this.value=='dd'){
		this.value = '';
	}
}

function changeChildren(text){
	var tbody = document.getElementById("children_age").getElementsByTagName("TBODY")[0];
	var aantal = document.getElementById("children").value;
	for (i=1; i<=10; i++){
		var element = document.getElementById("child_"+i);
		if (element){
			if (i>aantal){
				tbody.removeChild(element);
			}
		} else {
			if (i<=aantal){
				var row = document.createElement("TR");
				row.id = "child_"+i;
				var td1 = document.createElement("TD");
				td1.className = "formitem";
				td1.style.width = '150px';
				td1.appendChild(document.createTextNode(text+i));
				var td2 = document.createElement("TD");
				
				var inputElementM = document.createElement("select");
				inputElementM.className = 'inputtext';
				inputElementM.id = 'child_maand_'+i;
				inputElementM.name = 'child_maand_'+i;
				inputElementM.style.width = '40px';
				for (j=1; j<=12; j++){
					var objOption = document.createElement("option");
					objOption.text=j;
					objOption.value=j;
					inputElementM.options.add(objOption);
				}

				var inputElementD = document.createElement("select");
				inputElementD.className = 'inputtext';
				inputElementD.id = 'child_dag_'+i;
				inputElementD.name= 'child_dag_'+i;
				inputElementD.style.width = '40px';
				for (j=1; j<=31; j++){
					var objOption = document.createElement("option");
					objOption.text=j;
					objOption.value=j;
					inputElementD.options.add(objOption);
				}

				var inputElementY = document.createElement("select");
				inputElementY.className = 'inputtext';
				inputElementY.id = 'child_jaar_'+i;
				inputElementY.name = 'child_jaar_'+i;
				inputElementY.style.width = '60px';

				var now = new Date();
				var year = now.getFullYear();
				for (j=year; j>=1982; j--){
					var objOption = document.createElement("option");
					objOption.text=j;
					objOption.value=j;
					inputElementY.options.add(objOption);
				}

				td2.appendChild(inputElementD);
				td2.appendChild(document.createTextNode(" "));
				td2.appendChild(inputElementM);
				td2.appendChild(document.createTextNode(" "));
				td2.appendChild(inputElementY);
				row.appendChild(td1);
				row.appendChild(td2);
				tbody.appendChild(row);
			}
		}
	}
}

function showMovie(width, height, url){
	var msg = "";

	msg += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"675\" height=\"420\" style=\"background-image: url('/images/empty.gif');\">\n";
	msg += "<tr>";
		msg += "<td height=\"30\" style=\"background-image: url('/images/shade_top_left.gif'); background-repeat: no-repeat; background-position: right bottom;\"></td>";
		msg += "<td style=\"background-image: url('/images/shade_top_middle.gif'); background-repeat: repeat-x; background-position: bottom;\"></td>";
		msg += "<td style=\"background-image: url('/images/shade_top_right.gif'); background-repeat: no-repeat; background-position: left bottom;\"></td>";
	msg += "</tr>";
	msg += "<tr>";
		msg += "<td width=\"40\" style=\"background-image: url('/images/shade_left_middle.gif'); background-repeat: repeat-y; background-position: right;\"></td>";
		msg += "<td align=\"center\" valign=\"middle\">\n";
			msg += "<object width=\"595\" height=\"360\"><param name=\"movie\" value=\""+url+"\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\""+url+"\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"595\" height=\"360\"></embed></object>";		
		msg += "</td><td valign=\"top\" width=\"40\" align=\"center\" style=\"background-image: url('/images/shade_right_middle.gif'); background-repeat: repeat-y; background-position: left;\">";
			msg += "<a href=\"javascript:hideMovieBox();\"><img src=\"/images/close.gif\"></a>";			
		msg += "</td>";
	msg += "</tr>\n";
	msg += "<tr>";
		msg += "<td height=\"30\" style=\"background-image: url('/images/shade_bottom_left.gif'); background-repeat: no-repeat; background-position: right top;\"></td>";
		msg += "<td style=\"background-image: url('/images/shade_bottom_middle.gif'); background-repeat: repeat-x; background-position: top;\"></td>";
		msg += "<td style=\"background-image: url('/images/shade_bottom_right.gif'); background-repeat: no-repeat; background-position: left top;\"></td>";
	msg += "</tr>";
	msg += "</table>\n";	

	showInfoBox(width, height, msg);
}

function showInfoBox(width, height, msg){
	buildDiv(width, height);
	var infoDiv = document.getElementById('infoDiv');
	infoDiv.innerHTML = msg;
}

function buildDiv(width, height){
	var objOverlay = document.getElementById('infoOverlay');
	var objDivbox = document.getElementById('infoBox');

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// set height of Overlay to take up whole page and show
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';

	// center divbox and make sure that the top and left values are not negative
	// and the image placed outside the viewport
	var divboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - height) / 2);
	var divboxLeft = ((arrayPageSize[0] - 20 - width) / 2);

	objDivbox.style.top = (divboxTop < 0) ? "0px" : divboxTop + "px";
	objDivbox.style.left = (divboxLeft < 0) ? "0px" : divboxLeft + "px";

	objDivbox.style.display = 'block';

	// After image is loaded, update the overlay height as the new image might have
	// increased the overall page height.
	arrayPageSize = getPageSize();
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	
	objDivbox.style.width = width + 'px';
	objDivbox.style.height = height + 'px';
	objDivbox.style.overflow = 'auto';
}

function initInfoBox(){
	var objBody = document.getElementsByTagName("body").item(0);
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','infoOverlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	// create Divbox div, same note about styles as above
	var objDivbox = document.createElement("div");
	objDivbox.setAttribute('id','infoBox');
	objDivbox.style.display = 'none';
	objDivbox.style.position = 'absolute';
	objDivbox.style.zIndex = '100';	

	var infoDiv = document.createElement("div");
	infoDiv.setAttribute('id','infoDiv');

	objDivbox.appendChild(infoDiv);

	objBody.insertBefore(objDivbox, objOverlay.nextSibling);
}

function hideMovieBox(){
	var objOverlay = document.getElementById('infoOverlay');
	var objDivbox = document.getElementById('infoBox');

	objOverlay.style.display = 'none';
	objDivbox.style.display = 'none';

	var infoDiv = document.getElementById('infoDiv');
	infoDiv.innerHTML = "";

	if (document.getElementById('vraagteken')){
		var objVraagteken = document.getElementById('vraagteken');
		objVraagteken.startInterval();
	}
}

addLoadEvent(initInfoBox);

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}



//
// 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;
}

