/**
 * Copyright (c)
 * Adrian Hangan
 * Programator Web
 * Edil Imobiliare IT Team
 */

$(document).ready(function(){
	
	var adresa_host = window.location.hostname;
    var site_language='';
    if(adresa_host.search(/en\./i)!='-1') site_language='en';
    else {
    	if(adresa_host.search(/fr\./i)!='-1') site_language='fr';
    	else site_language='ro';
    }
	
	
	function sendGET(pagina,var_data,rez_div){	
		$.ajax({
			  url: pagina,
			  type: "GET",
			  data: var_data,
			  
			  statusCode: {
			  	404: function(){
			  		alert('page not found');
			  	}
			  },

			  success: function(result){
				//alert("success!" + result);
				$(rez_div).html(result);
			  }
		});
	}
	
	//setarea (on page load) paginii curente pentru index 	
	var pagina_curenta = 1;
	
	$("#index_one").height(27);
	$("#index_one").width(27);
	$("#index_one").css("margin-bottom","-3px");
	
	//id-ul paginii curente
	var id_page = "";
	function detCurentPage(){
		if(pagina_curenta == 1){
			id_page = "#index_one";
		}
		if(pagina_curenta == 2){
			id_page = "#index_two";
		}
		if(pagina_curenta == 3){
			id_page = "#index_three";
		}
		if(pagina_curenta == 4){
			id_page = "#index_four";
		}
		if(pagina_curenta == 5){
			id_page = "#index_five";
		}
		if(pagina_curenta == 6){
			id_page = "#index_six";
		}
		
	}
	//efectul de mouse over pentru paginarea din index
	//stanga_dublu.png
	$('#index_first').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		detCurentPage();
				$(id_page).css("height","20px");
				$(id_page).css("width","20px");
				$(id_page).css("margin-bottom","0px");
				
				$("#index_first").css("height","27px");
				$("#index_first").css("width","27px");
				$("#index_first").css("margin-bottom","-3px");
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		detCurentPage();
				$(id_page).css("height","27px");
				$(id_page).css("width","27px");
				$(id_page).css("margin-bottom","-3px");
				
				$("#index_first").css("height","20px");
				$("#index_first").css("width","20px");
				$("#index_first").css("margin-bottom","0px");
		 	}
	);
	//stanga.png
	$('#index_previous').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		detCurentPage();
				$(id_page).css("height","20px");
				$(id_page).css("width","20px");
				$(id_page).css("margin-bottom","0px");
				
				$("#index_previous").css("height","27px");
				$("#index_previous").css("width","27px");
				$("#index_previous").css("margin-bottom","-3px");
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		detCurentPage();
				$(id_page).css("height","27px");
				$(id_page).css("width","27px");
				$(id_page).css("margin-bottom","-3px");
				
				$("#index_previous").css("height","20px");
				$("#index_previous").css("width","20px");
				$("#index_previous").css("margin-bottom","0px");
		 	}
	);
	
	//1_index.png
	$('#index_one').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 1){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_one").css("height","27px");
					$("#index_one").css("width","27px");
					$("#index_one").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 1){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
					
					$("#index_one").css("height","20px");
					$("#index_one").css("width","20px");
					$("#index_one").css("margin-bottom","0px");
					
				}
		 	}
	);
	
	//2_index.png
	$('#index_two').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 2){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
				
					$("#index_two").css("height","27px");
					$("#index_two").css("width","27px");
					$("#index_two").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 2){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
				
					$("#index_two").css("height","20px");
					$("#index_two").css("width","20px");
					$("#index_two").css("margin-bottom","0px");
					
				}
		 	}
	);
	
	//3_index.png
	$('#index_three').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 3){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
				
					$("#index_three").css("height","27px");
					$("#index_three").css("width","27px");
					$("#index_three").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 3){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
				
					$("#index_three").css("height","20px");
					$("#index_three").css("width","20px");
					$("#index_three").css("margin-bottom","0px");
					
				}
		 	}
	);
	
	//4_index.png
	$('#index_four').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 4){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
				
					$("#index_four").css("height","27px");
					$("#index_four").css("width","27px");
					$("#index_four").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 4){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
				
					$("#index_four").css("height","20px");
					$("#index_four").css("width","20px");
					$("#index_four").css("margin-bottom","0px");
				}
		 	}
	);
	
	//5_index.png
	$('#index_five').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 5){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
				
					$("#index_five").css("height","27px");
					$("#index_five").css("width","27px");
					$("#index_five").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 5){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
				
					$("#index_five").css("height","20px");
					$("#index_five").css("width","20px");
					$("#index_five").css("margin-bottom","0px");
				}
		 	}
	);
	
	//6_index.png
	$('#index_six').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		if(pagina_curenta != 6){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
				
					$("#index_six").css("height","27px");
					$("#index_six").css("width","27px");
					$("#index_six").css("margin-bottom","-3px");
					
				}
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		if(pagina_curenta != 6){
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
				
					$("#index_six").css("height","20px");
					$("#index_six").css("width","20px");
					$("#index_six").css("margin-bottom","0px");
				}
		 	}
	);
	
	//dreapta.png
	$('#index_next').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		detCurentPage();
				$(id_page).css("height","20px");
				$(id_page).css("width","20px");
				$(id_page).css("margin-bottom","0px");
				
				$("#index_next").css("height","27px");
				$("#index_next").css("width","27px");
				$("#index_next").css("margin-bottom","-3px");
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		detCurentPage();
				$(id_page).css("height","27px");
				$(id_page).css("width","27px");
				$(id_page).css("margin-bottom","-3px");
				
				$("#index_next").css("height","20px");
				$("#index_next").css("width","20px");
				$("#index_next").css("margin-bottom","0px");
		 	}
	);
	
	//stanga_dublu.png
	$('#index_last').hover(
			function() {
		 		$(this).css('cursor','pointer');
		 		detCurentPage();
				$(id_page).css("height","20px");
				$(id_page).css("width","20px");
				$(id_page).css("margin-bottom","0px");
				
				$("#index_last").css("height","27px");
				$("#index_last").css("width","27px");
				$("#index_last").css("margin-bottom","-3px");
		 	}, 
		 	function() {
		 		$(this).css('cursor','auto');
		 		detCurentPage();
				$(id_page).css("height","27px");
				$(id_page).css("width","27px");
				$(id_page).css("margin-bottom","-3px");
				
				$("#index_last").css("height","20px");
				$("#index_last").css("width","20px");
				$("#index_last").css("margin-bottom","0px");
		 	}
	);
	
	//actiunile de pe butoanele de la paginare :)
	$("#index_first").click(
			function(){
				if(pagina_curenta != 1){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_one").css("height","27px");
					$("#index_one").css("width","27px");
					$("#index_one").css("margin-bottom","-3px");
					
					sendGET("actions/paginare_index.php", "start=0&l="+site_language, ".content_index");
					
					pagina_curenta = 1;
				}
			}
	);
	
	$("#index_previous").click(
			function(){	
				if(pagina_curenta != 1){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					pagina_curenta = pagina_curenta - 1;
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
					
					var start_limit = (pagina_curenta - 1) * 9;
					
					sendGET("actions/paginare_index.php", "start=" + start_limit + "&l="+site_language, ".content_index");
					
				}
				
			}
	);
	
	$("#index_one").click(
			function(){
				if(pagina_curenta != 1){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_one").css("height","27px");
					$("#index_one").css("width","27px");
					$("#index_one").css("margin-bottom","-3px");
					
					pagina_curenta = 1;
					
					sendGET("actions/paginare_index.php", "start=0&l="+site_language, ".content_index");
				}
			}
	);
	
	$("#index_two").click(
			function(){
				if(pagina_curenta != 2){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_two").css("height","27px");
					$("#index_two").css("width","27px");
					$("#index_two").css("margin-bottom","-3px");
					
					pagina_curenta = 2;
					sendGET("actions/paginare_index.php", "start=9&l="+site_language, ".content_index");
				}
			}
	);
	
	$("#index_three").click(
			function(){
				if(pagina_curenta != 3){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_three").css("height","27px");
					$("#index_three").css("width","27px");
					$("#index_three").css("margin-bottom","-3px");
					
					pagina_curenta = 3;
				
					sendGET("actions/paginare_index.php", "start=18&l="+site_language, ".content_index");
				}
			}
	);
	
	$("#index_four").click(
			function(){
				if(pagina_curenta != 4){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_four").css("height","27px");
					$("#index_four").css("width","27px");
					$("#index_four").css("margin-bottom","-3px");
					
					pagina_curenta = 4;
				
					sendGET("actions/paginare_index.php", "start=27&l="+site_language, ".content_index");
				}
				
			}
	);
	
	$("#index_five").click(
			function(){
				if(pagina_curenta != 5){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_five").css("height","27px");
					$("#index_five").css("width","27px");
					$("#index_five").css("margin-bottom","-3px");
					
					pagina_curenta = 5;
				
					sendGET("actions/paginare_index.php", "start=36&l="+site_language, ".content_index");
				}
				
			}
	);
	
	$("#index_six").click(
			function(){
				if(pagina_curenta != 6){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_six").css("height","27px");
					$("#index_six").css("width","27px");
					$("#index_six").css("margin-bottom","-3px");
					
					pagina_curenta = 6;
				
					sendGET("actions/paginare_index.php", "start=45&l="+site_language, ".content_index");
				}
				
			}
	);
	
	$("#index_next").click(
			function(){
				if(pagina_curenta != 6){
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					pagina_curenta = pagina_curenta + 1;
					detCurentPage();
					$(id_page).css("height","27px");
					$(id_page).css("width","27px");
					$(id_page).css("margin-bottom","-3px");
					
					var start_limit = (pagina_curenta - 1) * 9;
					
					sendGET("actions/paginare_index.php", "start=" + start_limit + "&l="+site_language, ".content_index");
					
				}
				
			}
	);
	
	$("#index_last").click(
			function(){
				if(pagina_curenta != 6){
					
					detCurentPage();
					$(id_page).css("height","20px");
					$(id_page).css("width","20px");
					$(id_page).css("margin-bottom","0px");
					
					$("#index_six").css("height","27px");
					$("#index_six").css("width","27px");
					$("#index_six").css("margin-bottom","-3px");
					
					sendGET("actions/paginare_index.php", "start=45&l="+site_language, ".content_index");
					
					pagina_curenta = 6;
				}
				
			}
	);
	
});
