$(document).ready(function () {

	$('#nextPeoplePage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p + 1;
		
		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
		
		$('#'+list[0]).html("<div class='loader'><img src='images/ajax-loader.gif'></div>");
		
		if(nPage > $('#'+list[0]+'_pages').val()){
			nPage = 1;
		}
		
		var from = parseInt($('#ageFrom').val());
		var to = parseInt($('#ageTo').val());
		
		$.get("ajax/showModels.asp",{ kjonn: list[0], page: nPage, from: from, to: to }, function(data){
			$('#'+list[0]).html(data);
		});
		
		$('#prevPeoplePage').attr('class',nPage);
		$('#nextPeoplePage').attr('class',nPage);

	});
	
	$('#prevPeoplePage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p - 1;
		
		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
		
		$('#'+list[0]).html("<div class='loader'><img src='images/ajax-loader.gif'></div>");
		
		if(nPage == 0){
			nPage = $('#'+list[0]+'_pages').val();
		}
		
		var from = parseInt($('#ageFrom').val());
		var to = parseInt($('#ageTo').val());
		
		$.get("ajax/showModels.asp",{ kjonn: list[0], page: nPage, from: from, to: to }, function(data){
			$('#'+list[0]).html(data);
		});
		
		$('#prevPeoplePage').attr('class',nPage);
		$('#nextPeoplePage').attr('class',nPage);

	});
	
	$('#nextActorPage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p + 1;

		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
			
		$('#'+list[0]).html("<div class='loader'><img src='images/ajax-loader.gif'></div>");
		
		if(nPage > $('#'+list[0]+'_pages').val()){
			nPage = 1;
		}

		var from = parseInt($('#ageFrom').val());
		var to = parseInt($('#ageTo').val());
		
		$.get("ajax/showActors.asp",{ page: nPage, gender: list[0], from: from, to: to }, function(data){
			$('#'+list[0]).html(data);
		});
		
		$('#prevActorPage').attr('class',nPage);
		$('#nextActorPage').attr('class',nPage);

	});
	
	$('#prevActorPage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p - 1;

		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
		
		$('#'+list[0]).html("<div class='loader'><img src='images/ajax-loader.gif'></div>");
		
		if(nPage == 0){
			nPage = $('#'+list[0]+'_pages').val();
		}

		var from = parseInt($('#ageFrom').val());
		var to = parseInt($('#ageTo').val());
		
		$.get("ajax/showActors.asp",{ page: nPage, gender: list[0], from: from, to: to }, function(data){
			$('#'+list[0]).html(data);
		});
		
		$('#prevActorPage').attr('class',nPage);
		$('#nextActorPage').attr('class',nPage);

	});
	
	$('#nextPage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p + 1;
		
		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
		
		if(nPage > $('#'+list[0]+'_pages').val()){
			nPage = 1;
		}
		
		$('.pagin').hide();
		$('.page_'+nPage).show();
		
		$('#prevPage').attr('class',nPage);
		$('#nextPage').attr('class',nPage);

	});
	
	$('#prevPage').click(function() {
	
		var p = parseInt($(this).attr('class'));

		var nPage = p - 1;
		
		var cl = $('li.on').attr('class');
		var list = cl.split(' ');
		
		if(nPage == 0){
			nPage = $('#'+list[0]+'_pages').val();
		}
		
		$('.pagin').hide();
		$('.page_'+nPage).show();
		
		$('#prevPage').attr('class',nPage);
		$('#nextPage').attr('class',nPage);

	});
	
	$('.movie').click(function() {
	
		var movie = $(this).attr('id');
		
		$.get("ajax/showMovie.asp",{ movie: movie },function(data){
			$('#moviePlayer').html(data);
			$('#moviePlayer').show();
		});
	
	});
	
	$('#ageFromUp').click(function() {
	
		var val = parseInt($('#ageFrom').val()) + 1;
		var newval = 0;
		
		if(val >= 0){
			newval = val;
		}
		
		if(newval > 100){
			newval = 100;
		}
			
		$('#ageFrom').attr('value', newval);
	
	});
	
	$('#ageFromDown').click(function() {
	
		var val = parseInt($('#ageFrom').val()) - 1;
		var newval = 0;
		
		if(val >= 0){
			newval = val;
		}
		
		if(newval > 100){
			newval = 100;
		}
			
		$('#ageFrom').attr('value', newval);
	
	});
	
	$('#ageToUp').click(function() {
	
		var val = parseInt($('#ageTo').val()) + 1;
		var newval = 0;
		
		if(val >= 0){
			newval = val;
		}
		
		if(newval > 100){
			newval = 100;
		}
			
		$('#ageTo').attr('value', newval);
	
	});
	
	$('#ageToDown').click(function() {
	
		var val = parseInt($('#ageTo').val()) - 1;
		var newval = 0;
		
		if(val >= 0){
			newval = val;
		}
		
		if(newval > 100){
			newval = 100;
		}
			
		$('#ageTo').attr('value', newval);
	
	});
	
	$('#ageform').submit(function() {
	
	});

});

function showImage(img){
	
	$('.big_image').html('<img src="'+img+'" height="300">');

}

function showDiv(id){

	var cl = $('li.on').attr('class');
	
	if(cl != undefined){
		var list = cl.split(" ");
		$('li.on').attr('class',list[0])
	}

	$('li.'+id).attr('class', id +' on');
	
	if(id == 'female' || id == 'male'){
		$('#prevPeoplePage').attr('class','1');
		$('#nextPeoplePage').attr('class','1');
	}

	$('.hide').hide();
	$('#'+id).show();
}


function showVideo(video){
	$('#moviePlayer').show();

	$('#moviePlayer').html('<a href="javascript:;" class="closePlayer" onclick="$(\'#moviePlayer\').hide()"><img src="images/close.gif" border="0"></a><object width="425" height="344"><param name="movie" value="'+video+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+video+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');
}
