var temp = new Array();
	temp['page'] = 2;

$(document).ready(function(){
	if(document.location.hash != '') {
		document.location.hash = '';
	}
	$('#search').submit(function(){
		$('#results').html('<div style="text-align: center; padding: 10px 0;"><img src="sella/search-load.gif" /></div>');
		if($('#search-input').val() != '') {
			$.ajax({
				url: '?ajax=1&search=1&keywords='+$('#search-input').val().replace(' ', '-'),
				success: function(html){
					$('#load-more-li').css('display', 'block');
					if(html.length <= 484) {
						alert('There are no results.');
						$('#results').html('<li>Enter keywords above and click go to view the results</li>');
						$('#load-more-li').css('display', 'none');
						return true;
					}
					$('#results').html(html);
				}
			});
			$('#search-input').blur();
		} else {
			alert('Please enter at least one keyword!');
		}
		return false;
	});
});

window.onorientationchange = function() {
	var orientation = window.orientation;
	switch(orientation) {
		case 0:
		document.body.setAttribute("class","portrait");
		break;  
		case 90:
		document.body.setAttribute("class","landscape Left");
		break;
		case -90:  
		document.body.setAttribute("class","landscape Right");
		break;
	}
}

window.onbeforeunload = function() {
	$('#results').html('<li>Enter keywords above and click go to view the results</li>');
}

function loadMore() {
	$('#load-more-li img').css('display', 'block');
	$('#load-more').html('Loading...');
	$.ajax({
		url: '?ajax=1&keywords='+$('#search-input').val().replace(' ', '-')+'&page=page-'+temp['page'],
		success: function(html){
			if(html == '') {
				alert('There are no more results.');
				return true;
			}
			if($('#temp-div')) {
				$('#temp-div').remove();
			}
			$('#load-more-li').before('<div id="temp-div"></div>');
			$('#load-more-li').before(html);
			$('#load-more').html('Load 20 more results...');
			document.location.hash = '#temp-div';
			$('#load-more-li img').css('display', 'none');
			temp['page']++;
		}
	});
}