var current_image_number = 0;
var images = new Array();
images[0] = '../images/pic_creditcard.jpg';
images[1] = '../images/pic_ach.jpg';
images[2] = '../images/pic_services.jpg';
images[3] = '../images/pic_text.jpg';
images[4] = '../images/pic_marketing.jpg';


var texts = new Array();
texts[0] = '<font color = "#06536a">Credit Card Acceptance</font> <br><br>Experience better closing rates and increased cash flow.';
texts[1] = '<font color = "#06536a">ACH Integration</font> <br><br>Monitor payment and settlement activity 24/7 at RentPayment.com';
texts[2] = '<font color = "#06536a">Robust Services</font> <br><br>Learn more about accounting integration, check scanning and more.';
texts[3] = '<font color = "#06536a">Innovative Offerings</font> <br><br>Your residents can now pay rent right from their mobile phone!';
texts[4] = '<font color = "#06536a">Landlord Edition</font> <br><br>RentPayment Landlord is a time-tested product that will grow your business.';


var links = new Array();
links[0] = 'creditcards.html';
links[1] = 'echeck.html';
links[2] = 'services.html';
links[3] = 'rentbytext.html';
links[4] = 'marketingadvantage.html';


var total = 5;
var popup_open = 0;

function switch_image(image_number,auto) {
	//var effect = 'FadeIn';
	var effect = 'FadeIn';
	//var effect = 'DoubleDoor';
	
	if (auto) {
		//switching automatically
		if (current_image_number ==total - 1) {
			image_number = 0;
		}
		else {
			image_number = current_image_number + 1;
		}
	}
	
	var pic = images[image_number];
	var text = texts[image_number];
	var link = links[image_number];
	
		/****************************************************************************/
	$("#productcontainer_middle_text").fadeOut(1000, function () {
		$("#productcontainer_middle_text").html(text);
		$("#productcontainer_middle_text").fadeIn(1500);
    });

	$("#productlearnmore_button_link").attr("href", link)
	/****************************************************************************/

	
	if (image_number !=current_image_number) {
		switch (effect) {
			case "FadeIn":
				$("#productimage").ImageSwitch({Type: effect, NewImage: pic, EffectOriginal: false, Speed: 2400});
			break;
			
			case "FlyIn":
				$("#productimage").ImageSwitch({Type: effect, NewImage: pic, StartTop: 50, StartLeft: 100, Speed:2000});		
			break;
			
			case "DoubleDoor":
				$("#productimage").ImageSwitch({Type: effect, NewImage: pic}); 
			break;
		}
		current_image_number = image_number;
	}
	//alert(image_number+"   "+pic+"   "+current_image_number);
}


$(document).ready(function() {
	$("#productlearnmore_button").mouseover(function () {
		$(this).attr("src","../images/learnmore_hover.png");
	});

	$("#productlearnmore_button").mouseout(function () {
		$(this).attr("src","../images/learnmore.png");
	});
});

setInterval('switch_image(0,true)', 5000);

/****************************************************************************/

function mouse_position() {
	$().mousemove(function(e) {
		var x = e.pageX;
		var y = e.pageY;
		
		var tmp = $("#social_networking_button").position();
		
		var x_dif = Math.abs(x- tmp.left);
		var y_dif = Math.abs(y- tmp.top);
   
		if (x_dif >200 || y_dif >200) {
			hide_social_networking_popup();
		}
		return;
   }); 
}

function show_social_networking_popup() {
	if (popup_open ==0) {
		var tmp = $("#social_networking_button").position();
		
		var top = tmp.top - 120;
		var left = tmp.left - 25;
		
		$("#social_networking_popup").css("top",top);
		$("#social_networking_popup").css("left",left);
		$("#social_networking_popup").css("z-index",5000);
		
		var browser=navigator.appName;
		if (browser =="Microsoft Internet Explorer") {
			$("#social_networking_popup").show();
		}
		else {
			$("#social_networking_popup").fadeIn(400);
		}
		
		popup_open = 1;
		
		//<watch mouse position>
			cursor_timer = setInterval('mouse_position()', 500);
		//</watch mouse position>
	}
	
}

function hide_social_networking_popup() {
	if (popup_open ==1) {
		var browser=navigator.appName;
		if (browser =="Microsoft Internet Explorer") {
			$("#social_networking_popup").hide();
		}
		else {
			$("#social_networking_popup").fadeOut(400);
		}
		popup_open = 0;
		clearInterval(cursor_timer);
	}
}
/****************************************************************************/

function open_learn_more_window() {
	var opacity = 0.8;
	var fadeIn = 0;
	var fadeOut = 0;
	
	var browser = navigator.appName;
	if (browser =="Microsoft Internet Explorer") {
		opacity = 1;
		fadeIn = 0;
		fadeOut = 0;
	}	
	
	$("#lmw_errors").html('');
	$("#lmw_errors").hide();
	
	$.blockUI({ 
		message:  $("#learn_more_window"), 
	 
		css: { 
			width:          '516px', 
			height:         '419px', 
			position: 		'absolute',
    		left: 			'50%',
			top:			'50%',
    		'margin-left': 	'-258px',
    		'margin-top': 	'-209px',
			textAlign:      'center', 
			color:          '#000', 
			border:         '0px solid #aaa', 
			backgroundColor:'transparent',
			cursor:'normal'
		}, 
	 
		// styles for the overlay 
		overlayCSS:  { 
			backgroundColor:'#ffffff'
		}, 
	 
		// z-index for the blocking overlay 
		baseZ: 1000000, 
	 
		// set these to true to have the message automatically centered 
		centerX: true, // <-- only effects element blocking (page block controlled via css above) 
		centerY: true, 
	 
		// allow body element to be stetched in ie6; this makes blocking look better 
		// on "short" pages.  disable if you wish to prevent changes to the body height 
		allowBodyStretch: true, 
	 
		// be default blockUI will supress tab navigation from leaving blocking content; 
		constrainTabKey: true, 
	 
		// fadeIn time in millis; set to 0 to disable fadeIn on block 
		//fadeIn:  200, 
		fadeIn:  fadeIn, 
	 
		// fadeOut time in millis; set to 0 to disable fadeOut on unblock 
		//fadeOut:  400, 
		fadeOut:  fadeOut, 
	 
		// time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock 
		timeout: 0, 
	 
		// disable if you don't want to show the overlay 
		showOverlay: true, 
	 
		// if true, focus will be placed in the first available input field when 
		// page blocking 
		focusInput: true, 
	 
		// suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity) 
		applyPlatformOpacityRules: true, 
	 
		// callback method invoked when unblocking has completed; the callback is 
		// passed the element that has been unblocked (which is the window object for page 
		// blocks) and the options that were passed to the unblock call: 
		//     onUnblock(element, options) 
		onUnblock: null, 
	 
		// don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493 
		quirksmodeOffsetHack: 4 
	}); 
	
}

function submit_learn_more_window() {
	var name 			= $("#lmw_name").val();		
	var job_title 		= $("#lmw_job_title").val();		
	var company 		= $("#lmw_company").val();		
	var number_of_units = $("#lmw_number_of_units").val();		
	var phone			= $("#lmw_phone").val();		
	var email			= $("#lmw_email").val();		
	var comments		= $("#lmw_comments").val();		
	
	email = jQuery.trim(email);
	$("#lmw_email").val(email);
	
	name = jQuery.trim(name);
	$("#lmw_name").val(name);
	
	if (name.length <2) {
        $("#lmw_errors").html('Please enter your name');
        $("#lmw_errors").show();
        return false;
	}
	else {
        $("#lmw_errors").html('');
        $("#lmw_errors").hide();
	}
	
	if (!email.match(/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)) {
        $("#lmw_errors").html('Please enter a valid email address');
        $("#lmw_errors").show();
        return false;
    }
	else {
        $("#lmw_errors").html('');
        $("#lmw_errors").hide();
	}
	
	//<everything ok - send email>
		$.post("learn_more_email_ajax.php", {
			name: name,
			email:	email,
			job_title: job_title,
			company: company,
			number_of_units: number_of_units,
			phone: phone,
			comments: comments
		},
		function(data) {
			var jsonObject 	= eval('(' + data + ')');
			var email_sent 	= jsonObject.email_sent;
			
			if (email_sent) {
				$("#lmw_errors").html('Message sent. Thank you!');
				
				//<clear all fields>
					$("#lmw_name").val('');		
					$("#lmw_job_title").val('');		
					$("#lmw_company").val('');		
					$("#lmw_number_of_units").val('');		
					$("#lmw_phone").val('');		
					$("#lmw_email").val('');		
					$("#lmw_comments").val('');		
				//</clear all fields>
				
				return true;
			}
			else {
				$("#lmw_errors").html('Message not sent!<br/> Please try again later.');
				return true;
			}
		});
	//</everything ok - send email>
}

function close_learn_more_window() {
	$.unblockUI();
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/*
function popup_timer() {
	var current_timestamp = Math.floor(new Date().getTime() / 1000);
	
	//<try to read "pop-up" cookie>
		var cookie_timestamp = readCookie('popup');
	//</try to read "pop-up" cookie>
		
	if (cookie_timestamp) {
		//cookie set - check timestamp
		var time_difference = current_timestamp - cookie_timestamp;
		if (time_difference >=115) {
			//show the popup
			
			$('#jgrowl').jGrowl("", { 
				theme: 'rentpayment',
				glue: 'before',
				speed: 500,
				easing: 'easeInOutExpo',
				life:30000
			});
			
			clearInterval(popup_timer_id);
			eraseCookie('popup');
		}
	}
	else {
		//set cookie with current timestamp
		createCookie('popup',current_timestamp,1);
	}
}

var popup_timer_id = setInterval('popup_timer()', 3000);
*/
function yapnav_switch(menu_item,action) {
	var effect = 'FadeIn';
	switch (menu_item) {
		case 'ys':
			if (action =='over') {
				$("#g_ys").fadeOut(0,function() {
						$("#c_ys").fadeIn(0, function() {ys_status = 'over';});
					}				
				);
			}
			else {
				$("#c_ys").fadeOut(0,function() {
						$("#g_ys").fadeIn(0,function() {ys_status = 'out';});
					}				
				);
			}
		break;
		
		case 'rp':
			if (action =='over') {
				$("#g_rp").fadeOut(0,function() {
						$("#c_rp").fadeIn(0, function() {rp_status = 'over';});
					}				
				);
			}
			else {
				$("#c_rp").fadeOut(0,function() {
						$("#g_rp").fadeIn(0,function() {rp_status = 'out';});
					}				
				);
			}
		break;
		
		case 'vrp':
			if (action =='over') {
				$("#g_vrp").fadeOut(0,function() {
						$("#c_vrp").fadeIn(0, function() {vrp_status = 'over';});
					}				
				);
			}
			else {
				$("#c_vrp").fadeOut(0,function() {
						$("#g_vrp").fadeIn(0,function() {vrp_status = 'out';});
					}				
				);
			}
		break;
		
		case 'srp':
			if (action =='over') {
				$("#g_srp").fadeOut(0,function() {
						$("#c_srp").fadeIn(0, function() {srp_status = 'over';});
					}				
				);
			}
			else {
				$("#c_srp").fadeOut(0,function() {
						$("#g_srp").fadeIn(0,function() {srp_status = 'out';});
					}				
				);
			}
		break;
		
		case 'dp':
			if (action =='over') {
				$("#g_dp").fadeOut(0,function() {
						$("#c_dp").fadeIn(0, function() {dp_status = 'over';});
					}				
				);
			}
			else {
				$("#c_dp").fadeOut(0,function() {
						$("#g_dp").fadeIn(0,function() {dp_status = 'out';});
					}				
				);
			}
		break;
		
		case 'ip':
			if (action =='over') {
				$("#g_ip").fadeOut(0,function() {
						$("#c_ip").fadeIn(0, function() {ip_status = 'over';});
					}				
				);
			}
			else {
				$("#c_ip").fadeOut(0,function() {
						$("#g_ip").fadeIn(0,function() {ip_status = 'out';});
					}				
				);
			}
		break;
		
		case 'up':
			if (action =='over') {
				$("#g_up").fadeOut(0,function() {
						$("#c_up").fadeIn(0, function() {up_status = 'over';});
					}				
				);
			}
			else {
				$("#c_up").fadeOut(0,function() {
						$("#g_up").fadeIn(0,function() {up_status = 'out';});
					}				
				);
			}
		break;
	}
}

function reset_scrollbar() {
	//accordion links opened
	var links_opened = $("#accordion> .accordion_element:visible").size(); 
	
	if (links_opened ==0) {
		//all closed (if all links are closed, the size() will be 0
		
		//<show flash - hide picture>
			$("#content_left_picture").hide(0);
			$("#content_left_flash").show(0);
		//</show flash - hide picture>
	}
	else {
		//<show picture - hide flash>
			$("#content_left_flash").show(0);
			$("#content_left_picture").hide(0);
		//</show picture - hide flash>
	}

	scroller.reset();
	scrollbar.reset();
	
	//$('#accordion> .accordion_link > .accordion_element:hidden').children('div').css("background-position","0px 0px");
	
	if (scrollbar.disabled) {
		$("#content_right_scrollbar_container > .Scrollbar-Track").css("background","white");
		$("#content_right_scrollbar_container > .Scrollbar-Track > .Scrollbar-Handle").css("background","white");
	}
	else {
		$("#content_right_scrollbar_container > .Scrollbar-Track").css("background","url(../images/scrollbars/custom_scroll_bar.png)");
		$("#content_right_scrollbar_container > .Scrollbar-Track > .Scrollbar-Handle").css("background","url(../images/scrollbars/custom_scroller_small.jpg)");
	}
	
	clearInterval(scrollbar_timer_id);
}