// JavaScript Document

function activateDemoField() {
	if ($("#googledemo").val() == 'type your search here') {
		$("#googledemo").val("");
		$("#googledemo").css("color", "white");
	}
}

function deactivateDemoField() {
	if ($("#googledemo").val() == '') {
		$("#googledemo").css("color", "#828182");
		$("#googledemo").val("type your search here");
		$("#trydemo").show();
		$("#trydemobutton").hide();
	}
}

function init() {
	rotateImages();
	
	/*$("#googledemo").css("color", "#828182");
	$("#googledemo").val("type your search here");
	$("#googledemo").blur();
	$("#trydemobutton").hide();*/
	var browser=navigator.appName;
	
	if(/Safari/.test(navigator.userAgent)) {
		$("#taglinemask").attr("id","innertaglinemask");
	}
	
	//Sort out the install buttons
	if (navigator.userAgent.indexOf("Windows")!=-1 || navigator.userAgent.indexOf("Win32")!=-1) {
		//If this is Windows
		if (browser=="Microsoft Internet Explorer" && !navigator.userAgent.toLowerCase().match('msie 6')) {
			//If this is IE 7 or 8
			if ($("#publisherlink")) {
				$("#publisherlink").attr('href', "/html/WebMynd.Setup.exe");
			}
			if ($("#helplink")) {
				$("#helplink").attr('href',"iehelp.html");
			}
		} else if (navigator.userAgent.indexOf("Chrome")!=-1) {
			//This is Chrome on Windows
			if ($("#publisherlink")) {
				$("#publisherlink").attr('href', "/html/WebMynd.Setup.exe");
			}
			if ($("#installlink")) {
				$("#installlink").attr('href',"/html/WebMynd.Setup.exe");
			}
			if ($("#bottominstall")) {
				$("#bottominstall").attr('href',"/html/WebMynd.Setup.exe");
			}
		} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
			//This is Firefox on Windows
			if ($("#installlink")) {
				$("#installlink").attr('href',"https://addons.mozilla.org/en-US/firefox/downloads/latest/6416/addon-6416-latest.xpi");
			}
			if ($("#bottominstall")){
				$("#bottominstall").attr('href',"https://addons.mozilla.org/en-US/firefox/downloads/latest/6416/addon-6416-latest.xpi");
			}
		} else {
			//This is not Firefox or IE 7/8 or Chrome on Windows
			if ($("#installlink")) {
				$("#installlink").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			} 
			if ($("#publisherlink")) {
				$("#publisherlink").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			}
			if ($("#bottominstall")) {
				$("#bottominstall").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			}
		}
	} else {
		//This is not Windows
		if (navigator.userAgent.indexOf("Firefox")!=-1) {
			//This is Firefox on non-Windows
			if ($("#installlink")) {
				$("#installlink").attr('href',"https://addons.mozilla.org/en-US/firefox/downloads/latest/6416/addon-6416-latest.xpi");
			}
			if ($("#bottominstall")) {
				$("#bottominstall").attr('href',"https://addons.mozilla.org/en-US/firefox/downloads/latest/6416/addon-6416-latest.xpi");
			}
		} else if(navigator.userAgent.indexOf("Chrome")!=-1) {
			//This is Chrome on non-Windows
			if ($("#installlink")) {
				$("#installlink").attr('href',"/html/WebMynd.crx");
			}
			if ($("#bottominstall")) {
				$("#bottominstall").attr('href',"/html/WebMynd.crx");
			}
		} else {
			//This is not Firefox or Chrome on non-Windows
			if ($("#installlink")) {
				$("#installlink").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			} else {
				$("#publisherlink").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			}
			if ($("#bottominstall")) {
				$("#bottominstall").attr('href',"javascript:alert('WebMynd only supports Firefox 3, Internet Explorer 7/8 and Chrome web browsers at present.');");
			}
		}
	}
	
	//Hide any items that shouldn't be shown to IE users or should only be shown to IE users
	if (browser=="Microsoft Internet Explorer") {
		$(".noIE").hide();
	} else {
		$(".onlyIE").hide();
	}

        overwrite_cookie();
}

function demoSearchButton(event) {
	$("#trydemo").hide();
	$("#trydemobutton").show();
	var code = 0;
	if (event && event.which){
		code = event.which
	} else {
		code = event.keyCode //character code is contained in IE's keyCode property
	}
	if (code == 13) { 
		demoSearch();
	}
}

function demoSearch() {
	var query = $("#googledemo").val();
	window.open('http://www.webmynd.com/demo?query='+query, '_parent');
}

function overwrite_cookie() {
        document.cookie = 'styletext=; host=www.webmynd.com'
}

window.onscroll = odometer;
$(document).ready(init)