var locations = true;
var branch = 1;

$(document).ready(init);

function init(){

	showATM();
	locationATMChange();
	
	showFirstLocation();
	locationInfoChange();
	
	skinSelects();
	
	$(document).pngFix();
	
	addMenus();
	
	adjustTables();
	
	$(".hideWithoutJS").css("display", "inline");
	
	
}

//ATM and Location Functionality Start

function showATM(){
	$("#ATMTab").css('display', 'block');
	$("#branchSelect").removeAttr('disabled');
	$("#findSelect").removeAttr('disabled');
	
	$("#locations form").css("padding-left", "0px");
}

function locationATMChange(){
	$("#ATMTab").click(changeToATM);
	$("#locationsTab").click(changeToLocations);
}

function changeToATM(){
	if(locations){
		$("#ATMTab").css({'color' : '#FFF', 'background-color' : '#565759'});
		$("#ATMs").css('display', 'block');
		locations = false;
		changeFromLocations();
	}
}

function changeToLocations(){
	if(!locations){
		$("#locationsTab").css({'color' : '#FFF', 'background-color' : '#565759'});
		$("#locations").css('display', 'block');
		locations = true;
		changeFromATM();
	}
}

function changeFromATM(){
	$("#ATMTab").css({'color' : '#0000CC', 'background-color' : '#F7F8F8'});
	$("#ATMs").css('display', 'none');
}

function changeFromLocations(){
	$("#locationsTab").css({'color' : '#0000CC', 'background-color' : '#F7F8F8'});
	$("#locations").css('display', 'none');
}

//ATM and Location Functionality End



//Location on Change Functionality Start

function showFirstLocation(){
	branch = 1;
	$("#branchSelect").val("Main Branch");
}

function locationInfoChange(){
	$("#branchSelect").change(getBranchInfo);
}

function getBranchInfo(){
	var listNum = $("#branchSelect").val();
	var selectValue = $("#branchForm li:eq(" + listNum + ")").attr('title');
	$("#branch"+branch).css('display', 'none');
	$("#"+selectValue).css('display', 'block');
	branch = selectValue.slice(6,7);
}

//Location on Change Functionality End

function goSubmit(){
	var listNum = $("#findSelect").val();
	var url = $("#findForm li:eq(" + listNum + ")").attr('title');
	window.open(url, "_blank");
}

function skinSelects(){
	$('#leftNav').jelectbox({
		selectbox_id:'branchSelect', 
		width:'260px'
	});
	
	$('#internalBankLocations').jelectbox({
		selectbox_id:'branchSelect', 
		width:'200px'
	});
	
	$('#findForm').jelectbox({
		selectbox_id:'findSelect', 
		width:'310px'
	});
}

function addMenus(){
	$('li.headLink').hover(
		function() { $('.secondaryDrop', this).css('display', 'block'); $(".button span", this).css('background-position', 'right'); },
		function() { $('.secondaryDrop', this).css('display', 'none'); $(".button span", this).css('background-position', 'left'); }
	);
	
	$('li.subLink').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	);
}

function test(){
	$(".headLink a.button span").css("background-position", "right");
}

function adjustTables(){
	$("tr:odd").css({"background" : "none"});
}

//Print Functionality
function printArticle() {
	if (window.print) {
		window.print();
	}else if (agt.indexOf("mac") != -1) {
		alert("Press 'Cmd+p' on your keyboard to print article.");
	}else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}


