var prevent_slideup = false;
var slideup = null;

function check_slideups () {
	if (slideup) {
		$('ul', slideup).slideUp(0);
		slideup = null; 
	}
}

$(document).ready(function () {
	
	setInterval('check_slideups()', 1);
	
	$('#print_button').click(function(){
		window.print();
	});
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
	
	$('a.preventclick').click(function(e) { e.preventDefault(); });

	$('#master_menu li.main').hover(
		function () {
			$('ul', this).slideDown(0);
		},
		function () {
			if (prevent_slideup == false) {
				//$('ul', this).delay(350).slideUp(100);
				slideup = this;
			}
		}
	); 
	
	$('#master_menu li ul li.catrow').hover(
		function () {
			// hover in
			
			// Reset slideup prevention (incase we didnt walk over tot he right hand side)
			prevent_slideup = false;
			
			// Reset an open sides
			$('ul.side').css('display', 'none');
			
			// Whats the position of this item?
			var position = $(this).position();
			
			// Work out the ID of this item
			var id = $(this).attr('id').split('_')[1];
			
			// Does it have any children?
			if ($('#menuslide_' + id).length != 0) {
				$('#menuslide_' + id)
					.css('left', '238px')
					.css('top', position.top+24)
					.css('z-index', '999999')
					.css('display', '');
				prevent_slideup = true;
			}
		},
		function () {
			// hover out
		}
	);
	
	$('#master_menu ul.side').hover(
		function () {},
		function () {
			// Close it, and reset prevent slideup
			$(this).css('display:none');
			prevent_slideup = false;
		}
	);
	
	$('#master_menu ul.side li').hover(
		function () {
			$(this).css('background-image', 'url(/images/gpeg/backgrounds/grey_fade.jpg)');
		},
		function () {
			$(this).css('background-image', 'none');
		}
	);
	
	$('#print_page').click(function (e) {
		e.preventDefault();
		window.print();
	});
	
	$(".register").colorbox({height:"500px", width:"550px", scrolling:false, iframe:true});
	
	if ($.browser.msie == true && $.browser.version < 7) {
		$('#browser_warning').slideDown();
	}
	
	$('#browser_warning_close').click(function () {
		$('#browser_warning').slideUp();
	});
	
	$('#file_register_submit').click(function () {
		_gaq.push(['_trackPageview', '/price_and_availability']);
		return false;
	});
	
	$('.file_download_link').click(function () {
		//_gaq.push(['_trackPageview', '/file_registration']);
		console.log('link track');
		return false;
	});
});
