$(document).ready(function() {	
	// Ini Navigation
	$("#mainNav").menu();
	
	//sliding carousel Agents Homepage
	$('#agentsList').jcarousel({
		scroll: 5						   
	});
	$('#propertyGallery').jcarousel({
        vertical: true,
        scroll: 2					   
	});	
	$("#propertyGallery li:odd").css("background-color", "#bbbbff");
	$('#propertyGallery li:nth-child(odd)').addClass('block');

	
	//prepend span tag
	$("#quickLinks li a").prepend("<span></span>");
	$("#agentsList li a").prepend("<span></span>");
	
		
	$(".agents ul li:last-child").addClass("noMgn");
	$(".agents ul:last-child").addClass("noBdr");
	$(".agents ul:first-child").prepend("<span></span>");
	$(".properties ul:first-child").prepend("<span></span>");
	
	//$("div.listing-item:nth-child(odd)").addClass('item-divider');
	//$('#list-region ul').multilists({cols: 3, colWidth: 244	})
	//$('#list-region ul').multilists({ cols: 3 });
	//$('#list-region').columnizeList({cols:3,constrainWidth:0});
	
	
		
				$('#listRegion').easyListSplitter({ 
			colNumber: 3, direction: 'horizontal'
		});


	// PDF Link Styling
	$("a[href$='.pdf']").addClass("pdf");
	
/*$('#list-region ul').multilists({ cols: 3, colWidth: 240 }, function() {
	$(this).parent().hide();
});	*/
	
	
	$("#listings .listing-item:nth-child(even)").addClass('item-divider');
	$("#listings .listing-item li:last-child").css("margin", 0);
	$("#content #mainCol div.blog-post:last-child").css("border", "none");
	
	$("#pikame li:nth-child(even)").css("margin-right", 0);
	
	/*$("div.properties .listProperties dt:last-child").css("font-style", "italic");*/
	/*$("div.properties .listProperties dt:first-child").addClass("test");*/
	/*$("dt:nth-of-type(1)").addClass("testdd");*/
	$("#quickLinks li:last-child").css("margin", 0);
	$("div.properties dl.listProperties > dt:first-child").css("margin", 0);
	$("div.properties dl.listProperties > dd:first").css("margin", 0);
	
	$('#infoPlug div.slideContent').hide();
	$('#infoPlug .rgtCol div.slideContent').show();
	$('#infoPlug h3.expand').css('cursor', 'pointer');
	$('#infoPlug h3.expand').click(function() {
		if($(this).next('div.slideContent:visible').length > 0) {
			$(this).next('div.slideContent').slideUp();
			$(this).removeClass('open');
		} else {
			$(this).next('div.slideContent').slideDown();
			$(this).addClass('open');
		}
	});
/*
$('#infoPlug h3.expandAuto div.slideContent').hide();
$('#infoPlug h3.expandAuto').onload(function() {
	$('#infoPlug h3.expandAuto div.slideContent').show();
		if($(this).next('h3.expandAuto div.slideContent:visible').length > 0) {
			$(this).next('h3.expandAuto div.slideContent').slideUp();
			$(this).removeClass('open');
		} else {
			$(this).next('h3.expandAuto div.slideContent').slideDown();
			$(this).addClass('open');
		}
	});*/
	
	$('.lftCol h3:first-child').css('margin-top', 0);
	$('.rgtCol h3:first-child').css('margin-top', 0);
/*	$('#infoPlug h3').hover(function() {
		$(this).css('color', '#B32017');
	});*/
	
	

	//On Click Event Pagination
	$("#page_navigation").click(function() {
		$('#listings').css("display", "none");
		$('#listings').fadeIn("slow");
	});



});

function slideShow() {
	
	$('#banner-home a').css({opacity: 0.0});
	$('#banner-home a:first').css({opacity: 1});
	$('#banner-home .caption').css({opacity: 0.7});
	$('#banner-home .caption').css({width: $('#banner-home a').find('img').css('width')});
	$('#banner-home .content').html($('#banner-home a:first').find('img').attr('rel'))
	.animate({opacity: 1.0}, 400);
	setInterval('gallery()',6000);
}

function gallery() {
	
	var current = ($('#banner-home a.show')?  $('#banner-home a.show') : $('#banner-home a:first'));
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#banner-home a:first') :current.next()) : $('#banner-home a:first'));	
	var caption = next.find('img').attr('rel');	
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	$('#banner-home .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });	
	$('#banner-home .caption').animate({opacity: 0.7},100 ).animate({height: '120px'},500 );
	$('#banner-home .content').html(caption);
}


// Verification Newsletter
var fieldInfo = new Array(); 
fieldInfo.push("required,cm-f-ijcjj,Vous devez remplir le champs Prénom");
fieldInfo.push("required,cm-name,Vous devez remplir le champs Nom");
fieldInfo.push("required,kkkyhl-kkkyhl,Vous devez indiquer une addresse de courriel dans le champs Courriel");
fieldInfo.push("valid_email,cm-kkkyhl-kkkyhl,Veuillez indiquer une addresse de courriel valide");



function previous(){
	
	new_page = parseInt($('#current_page').val()) - 1;
	//if there is an item before the current active link run the function
	if($('.active_page').prev('.page_link').length==true){
		go_to_page(new_page);
		
	}
	
}

function next(){
	new_page = parseInt($('#current_page').val()) + 1;
	//if there is an item after the current active link run the function
	if($('.active_page').next('.page_link').length==true){

		go_to_page(new_page);
	}
	
}
function go_to_page(page_num){
	//get the number of items shown per page
	var show_per_page = parseInt($('#show_per_page').val());
	
	//get the element number where to start the slice from
	start_from = page_num * show_per_page;
	
	//get the element number where to end the slice
	end_on = start_from + show_per_page;
	
	//hide all children elements of content div, get specific items and show them
	$('#listings').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
	
	/*get the page link that has longdesc attribute of the current page and add active_page class to it
	and remove that class from previously active page link*/
	$('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');
	
	//update the current page input field
	$('#current_page').val(page_num);
}
