$(document).ready(function () {

	jQuery.fn.center = function () {
		var width = this.css("width");
		var height = this.css("height");
		var newWidth = width.substring('p', width.length - 2 );
		var newHeight = height.substring('p', height.length - 2 );
		this.css("position","absolute");
		this.css("top", ( $(window).height() / 2 ) - ( newHeight / 2 ) + $(window).scrollTop() + "px" );
		this.css("left", ( $(window).width() / 2 ) - ( newWidth / 2 ) + $(window).scrollLeft() + "px" );
		return this;
	}

	var date = new Date(),
		weekday = [],
		month = [];
		
	weekday[0] = "Sunday";
	weekday[1] = "Monday";
	weekday[2] = "Tuesday";
	weekday[3] = "Wednesday";
	weekday[4] = "Thursday";
	weekday[5] = "Friday";
	weekday[6] = "Saturday";
	
	month[0] = "January";
	month[1] = "February";
	month[2] = "March";
	month[3] = "April";
	month[4] = "May";
	month[5] = "June";
	month[6] = "July";
	month[7] = "August";
	month[8] = "September";
	month[9] = "October";
	month[10] = "November";
	month[11] = "December"; 
	
	$('.day').append(weekday[date.getDay()]);
	$('.month').append(month[date.getMonth()]);
	$('.date').append(date.getDate() + ",");
	$('.year').append(date.getFullYear());
	$('.time').append(date.toLocaleTimeString());
	
	var videoModal = $('#video-modal').overlay({
		closeOnEsc: true,
        closeOnClick: true,
        api: true,
		left: 'center',
		onClose: function () { 
			$('#video-modal').unwrap();
		}
	}),
		
		youtubeModal = $('#youtube-modal').overlay({
		closeOnEsc: true,
        closeOnClick: true,
        api: true,
		left: 'center',
		onClose: function () { 
			$('#youtube-modal').unwrap();
			$('#youtube-container').tubeplayer("destroy");
		}
    });

    $('.youtube').click(function () {
		$('#youtube-modal').wrap('<div class="modal-background"></div>');
		var videoID = $(this).attr('rel');
		$('#youtube-container').tubeplayer({
			initialVideo: videoID,
			width: 800,
			height: 600
		});
		youtubeModal.load();
		
		return false;
	});
		
	$('.video-link').click(function () {
            
		$('#video-modal').wrap('<div class="modal-background"></div>');

		videoModal.load();

        var videoUrl = $(this).attr('href'),
			flashvars = {},
			params = {
				allowFullScreen: "true",
				allowscriptaccess: "always"
			},
			attributes = {};
			
        swfobject.embedSWF(videoUrl, 'youtube-player', '800', '600', '9.0.0', '', flashvars, params, attributes);

        return false;
	});
	
	$('.external').bind('click', function() {
		$('html, body').animate({scrollTop:0}, 'slow');
		var href = $(this).attr('href');
		$('#Main').load('leaving.asp #Main', function(){
			$('#Continue').attr('href', href);
			$('#GoBack').attr('href', window.location);
		});
		return false;
	});
	
	$('.email').bind('click', function() {
		var mailto = "mailto:"
		var name = $(this).attr('rel');
		var address = '@suncrestbank.com';
		var fulladdress = mailto + name + address;
		var email = name + address;
		$.modal("<h2>Attention:</h2><p>E-mail sent from this site is not secure. Please do not send us information regarding account numbers or social security numbers.</p><p>Email: <a id='EmailAddress' href='mailto:'>Name</a></p>", {closeHTML : "<a href='#' class='close'>Close</a>", opacity : 85});
		//$.modal("<div id='EmailBackground'><div id='EmailPanel'><h2>Attention:</h2><p>E-mail sent from this site is not secure. Please do not send us information regarding account numbers or social security numbers.</p><p>Email: <a id='EmailAddress' href='mailto:'>Name</a></p><a class='close'>Close</a></div></div>");
		$('#EmailAddress').attr('href', fulladdress);
		$('#EmailAddress').html(email);
		$('#EmailBackground').css('display', 'block');
		$('.close').click(function() {
			$('#EmailBackground').css('display', 'none');
		})
		return false;
	});
});
