var headline_count1;
var headline_interval1;
var old_headline1 = 0;
var current_headline1 = 0;

var headline_count2;
var headline_interval2;
var old_headline2 = 0;
var current_headline2 = 0;

var headline_count3;
var headline_interval3;
var old_headline3 = 0;
var current_headline3 = 0;
 
$(document).ready(function(){

	var rText = $.ajax({
        url: "http://www.orissaproperty.com/cgi-bin/siteFunctions/getLatestProps.pl",
        async: false
    }).responseText;

    if (rText == null || rText == "") {
        document.getElementById("NotifOuter1").style.display = 'none';
        return;
    }

	var latestLists = rText.split("?");

	var finalMessage = "";
	var notifs = latestLists[0].split(":");
	var i;
	for(i = 0; i < notifs.length; i++){
		var aNotif = notifs[i].split(";");

		var type = "";
		if (aNotif[4] == "APARTMENTS_PUB") {
			type = " [Apartment]";
		}
		else if (aNotif[4] == "HOMES_PUB") {
			type = " [House]";
		}
		else if (aNotif[4] == "LAND_PUB") {
			type = " [Land]";
		}

		var price = aNotif[3];
		if (price && parseInt(price) > 100000) {
			price = parseFloat(aNotif[3]) / 100000;
			price = "Rs. " + price + " Lacs";
		}
		else {
			price = "";
		}
		var desc =  aNotif[2];
		if (desc.length > 50) {
			desc = desc.substring(0,50);
			desc += " ...";
		}
		finalMessage += "<div class=\"headline1\">";
		finalMessage += "<div class=\"NotifTitle\">" + "<img src=\"http://www.orissaproperty.com/cgi-bin/ImageUtils/showImage.pl?TableName=PROPERTY_PHOTOS_PUB&ImageAttribute=Photo_Size1&MimeTypeAttribute=Photo_MimeType&WhereClause=ParentTableName%3d%27" + aNotif[4] + "%27%20and%20ParentTableId%3d" + aNotif[0] +"\">" + "</div>";
		finalMessage += "<div class=\"NotifTitle\">" + aNotif[1] + type + "</div>";
		finalMessage += "<div class=\"NotifSummary\">" + desc + "</div>";
		finalMessage += "<div class=\"NotifSummary\">Price: " + price + "</div>";
		finalMessage += "<div class=\"NotifLink\"><a target=\"_blank\" href=\"http://www.orissaproperty.com/cgi-bin/commonFuncs/viewData.pl?TableName=" + aNotif[4] + "&Id=" + aNotif[0] + "\">Details</a></div></div>";
	}
	document.getElementById("NotifDiv1").innerHTML=finalMessage;

     // Setting the 
     headline_count1 = $("div.headline1").size();
     $("div.headline1:eq("+current_headline1+")").css('top','5px');
	 if (headline_count1 <= 1) {
        return;
    }
 
     headline_interval1 = setInterval(headline_rotate1,5000); //time in milliseconds
     $('#NotifDiv1').hover(function() {
         clearInterval(headline_interval1);
     }, function() {
         headline_interval1 = setInterval(headline_rotate1,5000); //time in milliseconds
         headline_rotate1();
     });

	finalMessage = "";
	notifs = latestLists[1].split(":");
	i;
	for(i = 0; i < notifs.length; i++){
		var aNotif = notifs[i].split(";");

		var desc =  aNotif[2];
		if (desc.length > 50) {
			desc = desc.substring(0,50);
			desc += " ...";
		}

		finalMessage += "<div class=\"headline2\">";
		finalMessage += "<div class=\"NotifTitle\">" + "<img src=\"http://www.orissaproperty.com/cgi-bin/ImageUtils/showImage.pl?TableName=PROPERTY_PHOTOS_PUB&ImageAttribute=Photo_Size1&MimeTypeAttribute=Photo_MimeType&WhereClause=ParentTableName%3d%27" + aNotif[4] + "%27%20and%20ParentTableId%3d" + aNotif[0] +"\">" + "</div>";
		finalMessage += "<div class=\"NotifTitle\">" + aNotif[1] + "</div>";
		finalMessage += "<div class=\"NotifSummary\">" + desc + "</div>";
		finalMessage += "<div class=\"NotifSummary\">Rent Rs.: " + aNotif[3] + "</div>";
		finalMessage += "<div class=\"NotifLink\"><a target=\"_blank\" href=\"http://www.orissaproperty.com/cgi-bin/commonFuncs/viewData.pl?TableName=" +  aNotif[4] + "&Id=" + aNotif[0] + "\">Details</a></div></div>";
	}
	document.getElementById("NotifDiv2").innerHTML=finalMessage;

     // Setting the 
     headline_count2 = $("div.headline2").size();
     $("div.headline2:eq("+current_headline2+")").css('top','5px');
	 if (headline_count2 <= 1) {
        return;
    }
 
     headline_interval2 = setInterval(headline_rotate2,5000); //time in milliseconds
     $('#NotifDiv2').hover(function() {
         clearInterval(headline_interval2);
     }, function() {
         headline_interval2 = setInterval(headline_rotate2,5000); //time in milliseconds
         headline_rotate2();
     });
});
 
function headline_rotate1() {
   current_headline1 = (old_headline1 + 1) % headline_count1; 
   $("div.headline1:eq(" + old_headline1 + ")").animate({top: -245},1000, function() {
     $(this).css('top','200px');
   });
   $("div.headline1:eq(" + current_headline1 + ")").show().animate({top: 10},1000);  
   old_headline1 = current_headline1;
}


function headline_rotate2() {
   current_headline2 = (old_headline2 + 1) % headline_count2;
   $("div.headline2:eq(" + old_headline2 + ")").animate({top: -245},1000, function() {
     $(this).css('top','200px');
   });
   $("div.headline2:eq(" + current_headline2 + ")").show().animate({top: 10},1000);
   old_headline2 = current_headline2;
}
/*
function headline_rotate3() {
   current_headline3 = (old_headline3 + 1) % headline_count3;
   $("div.headline3:eq(" + old_headline3 + ")").animate({top: -205},2000, function() {
     $(this).css('top','160px');
   });
   $("div.headline3:eq(" + current_headline3 + ")").show().animate({top: 10},2000);
   old_headline3 = current_headline3;
}
*/

