/*	BulkWords
	*********
	Javascript by RevenApps. Magic by jQuery.
*/

$(document).ready(function() {

	// Browser/OS sniffing (is evil)
	window.os = (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris');
	window.browser = function() {var b; if ($.browser.msie) b = 'msie'; if ($.browser.webkit) b = 'webkit'; if ($.browser.opera) b = 'opera'; if ($.browser.mozilla) b = 'mozilla'; return b;}();
	window.version = $.browser.version;
	
	/*	These following global vars are deprecated.
	 	All references to them should be replaced with conditional statements using the global vars
		window.os, window.browser and window.version	*/
	
		window.ie6 = ($.browser.msie && parseInt($.browser.version) <= 6);
		window.ie7 = ($.browser.msie && parseInt($.browser.version) == 7);
		window.ie8 = ($.browser.msie && parseInt($.browser.version) == 8);
	
	// Add browser and os as class name to body tag for browser/os specific hacks
	$('body').addClass('browser_is_' + window.browser + ' os_is_' + window.os);

	// IE6 upgrade script
	upgrade.init()

	//setup eventhandlers for the always available menu
	$('#btnLogin').click(function() {
		$.modaldialog.ajax(location.protocol + "//" + location.hostname + "/login/?action=ajaxForm", { modalClass: 'login' }, function() {
			$('.modal.login input:first').focus();
		});
		return false;
	});
	
	$('#btnLogout').click(function() {
		$.modaldialog.loading("Logging out, please wait");
		new Authenticater().Logout(function() {
			//redirect to homepage to avoid any possible issues with application state.
			location.href = location.protocol + "//" + location.hostname;
		}, function(data) {
			$.modaldialog.error(data);
		});
		return false;
	});
	
	// IE7 and IE8 hacks
	if (window.ie7 || window.ie8) {
		// Add pseudo pseudo :last-child classes for ie7 and ie8
		$('#header .nav li:last-child').addClass('last-child');
		
		// Add pseudo pseudo :focus on inputs
		$('form.user input[type=text], form.user input[type=password], form.user textarea').focus(function() {
			$(this).addClass('focus');
		}).blur(function() {
			$(this).removeClass('focus');
		})
	}
	
	// Empty inputs
	$('.empty').emptyfields();

	// Help boxes
	$('.box.help .btn_hide').bind('click', function() {
		// Cookie setten ofzo?
		$(this).parent().parent().fadeOut('fast').remove()
		return false;
	})

	// Page init if this page has it's own javascript file.
	if (typeof (pageDo) != "undefined") {
		pageDo.init();
	}
	
	// Bulkwords sales video
	$('.watch_video').click(function() {
		$.modaldialog.vimeo($(this).attr('href'), { width : 640, height : 360})
		return false;
	})
	
	// Footer
	$('.btn_mailafriend').click(function() {
		$.modaldialog.ajax(location.protocol + '//' + location.hostname + '/mailafriend/', { modalClass : 'mailafriend' }, function() {
			
		});
		return false;
	})
});

