$currItem = 0;
$currGalleryItem = 0;

$(document).ready(function() 
{
	$('#myform2').ajaxForm({ 
			target: '#responsediv2',
			beforeSubmit: showSpinner2
	}); 
});
function showSpinner2() { 
	var $out = $('#responsediv2');
	$out.html("<p class=\"center spinner\"><img src=\"http://www.cornerstoneproperty.ie/img/spinner.gif\" alt=\"Spinner\" /></p>");
	return true; 
} 

$(document).ready(function() 
{
	$('#myform1').ajaxForm({ 
			target: '#responsediv',
			beforeSubmit: showSpinner
	}); 
});
function showSpinner() { 
	var $out = $('#responsediv');
	$out.html("<p class=\"center spinner\"><img src=\"../img/spinner.gif\" alt=\"Spinner\" /></p>");
	return true; 
} 


$(document).ready(function() 
{

	$("input[@id=email_newsletter]").click(
		function () {
			$(this).attr('value', '');
		}
	);
	
	$("#side-menu ul li a.ttl").toggle(
		function () {
			$(this).removeClass("on");
			$(this).next().slideUp();
		},
		function () {
			$(this).addClass("on");
			$(this).next().slideDown();
		}
	);

	$("#page-content dl dt").toggle(
		function () {
			$(this).next().slideDown();
		},
		function () {
			$(this).next().slideUp();
		}
	);

	$("#property-news p.title a").toggle(
		function () {
			$(this).addClass("off");
			$(this).removeClass("on");
			$("#property-news #news-body").slideUp();
		},
		function () {
			$(this).addClass("on");
			$(this).removeClass("off");
			$("#property-news #news-body").slideDown();
		}
	);
	
	$s = $("#property-news #news-body #news-items div:eq("+$currItem+")");
	$s.show();
	
	$("#property-news #news-body a.next").click(
		function () {
			$noOfItems = $("#property-news #news-body #news-items div").length-1;
			$prevItem = $currItem;
			$currItem++;
			if ($currItem > $noOfItems){
				$currItem = 0;
				$prevItem = $noOfItems;
			}
			$s = $("#property-news #news-body #news-items div:eq("+$currItem+")");
			$h = $("#property-news #news-body #news-items div:eq("+$prevItem+")");
			$s.fadeIn();
			$h.hide();
		}
	);

	$("#property-news #news-body a.prev").click(
		function () {
			$noOfItems = $("#property-news #news-body #news-items div").length-1;
			$prevItem = $currItem;
			$currItem--;
			if ($currItem < 0){
				$currItem = $noOfItems;
				$prevItem = 0;
			}
			$s = $("#property-news #news-body #news-items div:eq("+$currItem+")");
			$h = $("#property-news #news-body #news-items div:eq("+$prevItem+")");
			$s.fadeIn();
			$h.hide();
		}
	);

	$g = $("#gallery3 ul li:eq("+$currGalleryItem+")");
	$g.show();
	var gd = $("#gallery3 ul li:eq("+$currGalleryItem+")").html();
	gd = gd.slice(gd.indexOf("alt=\"")+5);
	gd = gd.slice(0, gd.indexOf("\""));
	$("#gallery3 p:eq(3)").text(gd);
	$noOfPics = $("#gallery3 ul li").length;
	var num = ($currGalleryItem+1)+" / "+$noOfPics;
	$("#gallery3 p:eq(1)").text(num);
	
	$("#gallery3 p a.next").click(
		function () {
			$noOfPics = $("#gallery3 ul li").length-1;
			$prevGalleryItem = $currGalleryItem;
			$currGalleryItem++;
			if ($currGalleryItem > $noOfPics){
				$currGalleryItem = 0;
				$prevGalleryItem = $noOfPics;
			}
			$gs = $("#gallery3 ul li:eq("+$currGalleryItem+")");
			$gh = $("#gallery3 ul li:eq("+$prevGalleryItem+")");
			$gs.fadeIn();
			$gh.hide();
			var gd = $("#gallery3 ul li:eq("+$currGalleryItem+")").html();
			gd = gd.slice(gd.indexOf("alt=\"")+5);
			gd = gd.slice(0, gd.indexOf("\""));
			$("#gallery3 p:eq(3)").text(gd);
			var num = ($currGalleryItem+1)+" / "+($noOfPics+1);
			$("#gallery3 p:eq(1)").text(num);
		}
	);

	$("#gallery3 p a.prev").click(
		function () {
			$noOfPics = $("#gallery3 ul li").length-1;
			$prevGalleryItem = $currGalleryItem;
			$currGalleryItem--;
			if ($currGalleryItem < 0){
				$currGalleryItem = $noOfPics;
				$prevGalleryItem = 0;
			}
			$gs = $("#gallery3 ul li:eq("+$currGalleryItem+")");
			$gh = $("#gallery3 ul li:eq("+$prevGalleryItem+")");
			$gs.fadeIn();
			$gh.hide();
			var gd = $("#gallery3 ul li:eq("+$currGalleryItem+")").html();
			gd = gd.slice(gd.indexOf("alt=\"")+5);
			gd = gd.slice(0, gd.indexOf("\""));
			$("#gallery3 p:eq(3)").text(gd);
			var num = ($currGalleryItem+1)+" / "+($noOfPics+1);
			$("#gallery3 p:eq(1)").text(num);
		}
	);

});


