/*
 * DOM Window
 */
(function(a){a.fn.closeDOMWindow=function(b){if(!b){b={}}var c=function(c){if(b.anchoredClassName){var d=a("."+b.anchoredClassName);d.fadeOut("fast",function(){if(a.fn.draggable){d.draggable("destory").trigger("unload").remove()}else{d.trigger("unload").remove()}});if(b.functionCallOnClose){b.functionCallAfterClose()}}else{var e=a("#DOMWindowOverlay");var f=a("#DOMWindow");e.fadeOut("fast",function(){e.trigger("unload").unbind().remove()});f.fadeOut("fast",function(){if(a.fn.draggable){f.draggable("destroy").trigger("unload").remove()}else{f.trigger("unload").remove()}});a(window).unbind("scroll.DOMWindow");a(window).unbind("resize.DOMWindow");if(a.fn.openDOMWindow.isIE6){a("#DOMWindowIE6FixIframe").remove()}if(b.functionCallOnClose){b.functionCallAfterClose()}}};if(b.eventType){return this.each(function(d){a(this).bind(b.eventType,function(){c(this);return false})})}else{c()}};a.closeDOMWindow=function(b){a.fn.closeDOMWindow(b)};a.fn.openDOMWindow=function(b){var c=a.fn.openDOMWindow;c.defaultsSettings={anchoredClassName:"",anchoredSelector:"",borderColor:"#ccc",borderSize:"4",draggable:0,eventType:null,fixedWindowY:100,functionCallOnOpen:null,functionCallOnClose:null,height:500,loader:0,loaderHeight:0,loaderImagePath:"",loaderWidth:0,modal:0,overlay:1,overlayColor:"#000",overlayOpacity:"85",positionLeft:0,positionTop:0,positionType:"centered",width:500,windowBGColor:"#fff",windowBGImage:null,windowHTTPType:"get",windowPadding:10,windowSource:"inline",windowSourceID:"",windowSourceURL:"",windowSourceAttrURL:"href"};var d=a.extend({},a.fn.openDOMWindow.defaultsSettings,b||{});c.viewPortHeight=function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight};c.viewPortWidth=function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth};c.scrollOffsetHeight=function(){return self.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop};c.scrollOffsetWidth=function(){return self.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft};c.isIE6=typeof document.body.style.maxHeight==="undefined";var e=function(){var b=a("#DOMWindowOverlay");if(c.isIE6){var d=document.documentElement.offsetHeight+document.documentElement.scrollTop-4;var e=document.documentElement.offsetWidth-21;b.css({height:d+"px",width:e+"px"})}else{b.css({height:"100%",width:"100%",position:"fixed"})}};var f=function(){var b=document.documentElement.offsetHeight+document.documentElement.scrollTop-4;var c=document.documentElement.offsetWidth-21;a("#DOMWindowIE6FixIframe").css({height:b+"px",width:c+"px"})};var g=function(){var b=a("#DOMWindow");if(d.height+50>c.viewPortHeight()){b.css("left",Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(b.outerWidth()/2))}else{b.css("left",Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(b.outerWidth()/2));b.css("top",Math.round(c.viewPortHeight()/2)+c.scrollOffsetHeight()-Math.round(b.outerHeight()/2))}};var h=function(){var b=a("#DOMWindowLoader");if(c.isIE6){b.css({left:Math.round(c.viewPortWidth()/2)+c.scrollOffsetWidth()-Math.round(b.innerWidth()/2),position:"absolute"});b.css({top:Math.round(c.viewPortHeight()/2)+c.scrollOffsetHeight()-Math.round(b.innerHeight()/2),position:"absolute"})}else{b.css({left:"50%",top:"50%",position:"fixed"})}};var i=function(){var b=a("#DOMWindow");b.css("left",d.positionLeft+c.scrollOffsetWidth());b.css("top",+d.positionTop+c.scrollOffsetHeight())};var j=function(b){if(arguments[0]){a("."+b+" #DOMWindowLoader").remove();a("."+b+" #DOMWindowContent").fadeIn("fast",function(){if(d.functionCallOnOpen){d.functionCallOnOpen()}});a("."+b+".closeDOMWindow").click(function(){a.closeDOMWindow();return false})}else{a("#DOMWindowLoader").remove();a("#DOMWindow").fadeIn("fast",function(){if(d.functionCallOnOpen){d.functionCallOnOpen()}});a("#DOMWindow .closeDOMWindow").click(function(){a.closeDOMWindow();return false})}};var k=function(a){var b={};a.replace(/b([^&=]*)=([^&=]*)b/g,function(a,c,d){if(typeof b[c]!="undefined"){b[c]+=","+d}else{b[c]=d}});return b};var l=function(b){d.windowSourceID=a(b).attr("href")||d.windowSourceID;d.windowSourceURL=a(b).attr(d.windowSourceAttrURL)||d.windowSourceURL;d.windowBGImage=d.windowBGImage?"background-image:url("+d.windowBGImage+")":"";var l,m;if(d.positionType=="anchored"){var n=a(d.anchoredSelector).position();var o=n.left+d.positionLeft;var p=n.top+d.positionTop;a("body").append('<div class="'+d.anchoredClassName+'" style="'+d.windowBGImage+";background-repeat:no-repeat;padding:"+d.windowPadding+"px;overflow:auto;position:absolute;top:"+p+"px;left:"+o+"px;height:"+d.height+"px;width:"+d.width+"px;background-color:"+d.windowBGColor+";border:"+d.borderSize+"px solid "+d.borderColor+';z-index:10001"><div id="DOMWindowContent" style="display:none"></div></div>');if(d.loader&&d.loaderImagePath!==""){a("."+d.anchoredClassName).append('<div id="DOMWindowLoader" style="width:'+d.loaderWidth+"px;height:"+d.loaderHeight+'px;"><img src="'+d.loaderImagePath+'" /></div>')}if(a.fn.draggable){if(d.draggable){a("."+d.anchoredClassName).draggable({cursor:"move"})}}switch(d.windowSource){case"inline":a("."+d.anchoredClassName+" #DOMWindowContent").append(a(d.windowSourceID).children());a("."+d.anchoredClassName).unload(function(){a("."+d.windowSourceID).append(a("."+d.anchoredClassName+" #DOMWindowContent").children())});j(d.anchoredClassName);break;case"iframe":a("."+d.anchoredClassName+" #DOMWindowContent").append('<iframe frameborder="0" hspace="0" wspace="0" src="'+d.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1e3)+'" style="width:100%;height:100%;border:none;background-color:#fff;" class="'+d.anchoredClassName+'Iframe" ></iframe>');a("."+d.anchoredClassName+"Iframe").load(j(d.anchoredClassName));break;case"ajax":if(d.windowHTTPType=="post"){if(d.windowSourceURL.indexOf("?")!==-1){l=d.windowSourceURL.substr(0,d.windowSourceURL.indexOf("?"));m=k(d.windowSourceURL)}else{l=d.windowSourceURL;m={}}a("."+d.anchoredClassName+" #DOMWindowContent").load(l,m,function(){j(d.anchoredClassName)})}else{if(d.windowSourceURL.indexOf("?")==-1){d.windowSourceURL+="?"}a("."+d.anchoredClassName+" #DOMWindowContent").load(d.windowSourceURL+"&random="+(new Date).getTime(),function(){j(d.anchoredClassName)})}break}}else{if(d.overlay){a("body").append('<div id="DOMWindowOverlay" style="z-index:10000;display:none;position:absolute;top:0;left:0;background-color:'+d.overlayColor+";filter:alpha(opacity="+d.overlayOpacity+");-moz-opacity: 0."+d.overlayOpacity+";opacity: 0."+d.overlayOpacity+';"></div>');if(c.isIE6){a("body").append('<iframe id="DOMWindowIE6FixIframe"  src="blank.html"  style="width:100%;height:100%;z-index:9999;position:absolute;top:0;left:0;filter:alpha(opacity=0);"></iframe>');f()}e();var q=a("#DOMWindowOverlay");q.fadeIn("fast");if(!d.modal){q.click(function(){a.closeDOMWindow()})}}if(d.loader&&d.loaderImagePath!==""){a("body").append('<div id="DOMWindowLoader" style="z-index:10002;width:'+d.loaderWidth+"px;height:"+d.loaderHeight+'px;"><img src="'+d.loaderImagePath+'" /></div>');h()}a("body").append('<div id="DOMWindow" style="background-repeat:no-repeat;'+d.windowBGImage+";overflow:auto;padding:"+d.windowPadding+"px;display:none;height:"+d.height+"px;width:"+d.width+"px;background-color:"+d.windowBGColor+";border:"+d.borderSize+"px solid "+d.borderColor+'; position:absolute;z-index:10001"></div>');var r=a("#DOMWindow");switch(d.positionType){case"centered":g();if(d.height+50>c.viewPortHeight()){r.css("top",d.fixedWindowY+c.scrollOffsetHeight()+"px")}break;case"absolute":r.css({top:d.positionTop+c.scrollOffsetHeight()+"px",left:d.positionLeft+c.scrollOffsetWidth()+"px"});if(a.fn.draggable){if(d.draggable){r.draggable({cursor:"move"})}}break;case"fixed":i();break;case"anchoredSingleWindow":var n=a(d.anchoredSelector).position();var o=n.left+d.positionLeft;var p=n.top+d.positionTop;r.css({top:p+"px",left:o+"px"});break}a(window).bind("scroll.DOMWindow",function(){if(d.overlay){e()}if(c.isIE6){f()}if(d.positionType=="centered"){g()}if(d.positionType=="fixed"){i()}});a(window).bind("resize.DOMWindow",function(){if(c.isIE6){f()}if(d.overlay){e()}if(d.positionType=="centered"){g()}});switch(d.windowSource){case"inline":r.append(a(d.windowSourceID).children());r.unload(function(){a(d.windowSourceID).append(r.children())});j();break;case"iframe":r.append('<iframe frameborder="0" hspace="0" wspace="0" src="'+d.windowSourceURL+'" name="DOMWindowIframe'+Math.round(Math.random()*1e3)+'" style="width:100%;height:100%;border:none;background-color:#fff;" id="DOMWindowIframe" ></iframe>');a("#DOMWindowIframe").load(j());break;case"ajax":if(d.windowHTTPType=="post"){if(d.windowSourceURL.indexOf("?")!==-1){l=d.windowSourceURL.substr(0,d.windowSourceURL.indexOf("?"));m=k(d.windowSourceURL)}else{l=d.windowSourceURL;m={}}r.load(l,m,function(){j()})}else{if(d.windowSourceURL.indexOf("?")==-1){d.windowSourceURL+="?"}r.load(d.windowSourceURL+"&random="+(new Date).getTime(),function(){j()})}break}}};if(d.eventType){return this.each(function(b){a(this).bind(d.eventType,function(){l(this);return false})})}else{l()}};a.openDOMWindow=function(b){a.fn.openDOMWindow(b)}})(jQuery)


/*
 * Globals
 */
if(!window.console||!console.firebug){var names=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];window.console={};for(var i=0;i<names.length;++i){window.console[names[i]]=function(){}}}(function(a){a.fn.normaliseHeight=function(){var c=a(this);var b=[];var d=function(f,e){return f-e};a(c).each(function(){b.push(a(this).height())});b.sort(d);b.reverse();a(c).each(function(){a(this).height(b[0])})}})(jQuery);(function(a){a.fn.clickpanel=function(b){var c=a.extend({},a.fn.clickpanel.defaults,b);return this.each(function(){a(this).hover(function(){a("a",this).addClass("hover")},function(){a("a",this).removeClass("hover")}).click(function(){if(a("a:eq(0)",this).attr("rel")===c.rel){window.open(a("a:eq(0)",this).attr("href"));return false}else{location.href=a("a:eq(0)",this).attr("href");return false}}).css("cursor",c.cursor)})};a.fn.clickpanel.defaults={cursor:"pointer",rel:"external"}})(jQuery);(function(a){a.fn.rollover=function(b){var c=a.extend({},a.fn.rollover.defaults,b);return this.each(function(){a(this).hover(function(){this.src=this.src.split(c.strOff).join(c.strOn)},function(){this.src=this.src.split(c.strOn).join(c.strOff)})})};a.fn.rollover.defaults={strOn:"_on",strOff:"_off"}})(jQuery);function createCookie(c,d,e){if(e){var b=new Date();b.setTime(b.getTime()+(e*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+d+a+"; path=/"}function readCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)===" "){f=f.substring(1,f.length)}if(f.indexOf(e)===0){return f.substring(e.length,f.length)}}return null}function eraseCookie(a){createCookie(a,"",-1)}$(document).ready(function(){$("a[href][rel=external]").attr("target","_blank")});

/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 */
;(function($){$.fn.superfish=function(op){var sf=$.fn.superfish,c=sf.c,$arrow=$(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),over=function(){var $$=$(this),menu=getMenu($$);clearTimeout(menu.sfTimer);$$.showSuperfishUl().siblings().hideSuperfishUl();},out=function(){var $$=$(this),menu=getMenu($$),o=sf.op;clearTimeout(menu.sfTimer);menu.sfTimer=setTimeout(function(){o.retainPath=($.inArray($$[0],o.$path)>-1);$$.hideSuperfishUl();if(o.$path.length&&$$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}},o.delay);},getMenu=function($menu){var menu=$menu.parents(['ul.',c.menuClass,':first'].join(''))[0];sf.op=sf.o[menu.serial];return menu;},addArrow=function($a){$a.addClass(c.anchorClass).append($arrow.clone());};return this.each(function(){var s=this.serial=sf.o.length;var o=$.extend({},sf.defaults,op);o.$path=$('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){$(this).addClass([o.hoverClass,c.bcClass].join(' ')).filter('li:has(ul)').removeClass(o.pathClass);});sf.o[s]=sf.op=o;$('li:has(ul)',this)[($.fn.hoverIntent&&!o.disableHI)?'hoverIntent':'hover'](over,out).each(function(){if(o.autoArrows)addArrow($('>a:first-child',this));}).not('.'+c.bcClass).hideSuperfishUl();var $a=$('a',this);$a.each(function(i){var $li=$a.eq(i).parents('li');$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});});o.onInit.call(this);}).each(function(){var menuClasses=[c.menuClass];if(sf.op.dropShadows&&!($.browser.msie&&$.browser.version<7))menuClasses.push(c.shadowClass);$(this).addClass(menuClasses.join(' '));});};var sf=$.fn.superfish;sf.o=[];sf.op={};sf.IE7fix=function(){var o=sf.op;if($.browser.msie&&$.browser.version>6&&o.dropShadows&&o.animation.opacity!=undefined)
this.toggleClass(sf.c.shadowClass+'-off');};sf.c={bcClass:'sf-breadcrumb',menuClass:'sf-js-enabled',anchorClass:'sf-with-ul',arrowClass:'sf-sub-indicator',shadowClass:'sf-shadow'};sf.defaults={hoverClass:'sfHover',pathClass:'overideThisToUse',pathLevels:1,delay:800,animation:{opacity:'show'},speed:'normal',autoArrows:true,dropShadows:true,disableHI:false,onInit:function(){},onBeforeShow:function(){},onShow:function(){},onHide:function(){}};$.fn.extend({hideSuperfishUl:function(){var o=sf.op,not=(o.retainPath===true)?o.$path:'';o.retainPath=false;var $ul=$(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass).find('>ul').hide().css('visibility','hidden');o.onHide.call($ul);return this;},showSuperfishUl:function(){var o=sf.op,sh=sf.c.shadowClass+'-off',$ul=this.addClass(o.hoverClass).find('>ul:hidden').css('visibility','visible');sf.IE7fix.call($ul);o.onBeforeShow.call($ul);$ul.animate(o.animation,o.speed,function(){sf.IE7fix.call($ul);o.onShow.call($ul);});return this;}});})(jQuery);

(function($) {
    $.fn.normaliseHeight = function() {
        var obj = $(this);
        var h = [];
        var sortNumber = function(a,b){
            return a - b;
        }
        $(obj).each(function(){
            h.push($(this).height());
        });
        h.sort(sortNumber);
        h.reverse();
        $(obj).each(function(){
            $(this).height(h[0]);
        });
    };
})(jQuery);

$(document).ready(function(){
	$('a.wkd').each(function(){
		if ($.browser.webkit) {
			var x = $(this).attr('href');
			var f = x.slice(x.lastIndexOf("/")+1);
			$(this).attr('href','/common/downloads/'+f);
			$(this).attr('target','_self');
		}
	});

	$('a[rel=email]').each(function(){
		var ea = $(this).attr('href');
		var et = $(this).text();
		var em = (ea.indexOf(et)>-1) ? true : false;
		var ea = ea.replace(/#/,'@');
		var ea = ea.replace(/\*/g,'.');
		if (em) {
			$(this).text(ea.slice(7));
		}
		$(this).attr('href',ea);
	});
	
	$('a[rel=emailbasic]').each(function(){
		var ea = $(this).attr('href');
		var ea = ea.replace(/#/,'@');
		var ea = ea.replace(/\*/g,'.');
		$(this).attr('href',ea);
	});
	
	if($.browser.msie){
		$('body').addClass('ie');
		if($.browser.version == '7.0'){
			$('body').addClass('ie7');
		}
	}
	
	//sets location based on userip
	$('#userip').each(function(){
		var ipadd = 'http://api.hostip.info/get_html.php?ip='+$(this).val();
		try {
			$.get(ipadd, function(data) {
				$('#userlocation').val(data);
			});
		} catch(err) {
		}
	});
	
	//sets platform from user-agent
	$('#userplatform').each(function(){
		var p = navigator.platform;
		$(this).val(p);
	});
	
	//displays full user-agent
	$('#useragent').each(function(){
		var os = navigator.userAgent;
		$(this).val(os);
	});
	
	$('#menu').superfish({delay: 100, animation: {opacity:'show',height:'show'}, speed: 'fast', autoArrows: false, dropShadows: false});
	
	/*
	$('a[rel=lightbox]').fancybox({titlePosition: 'inside'});
	
	$('a.imgpop').fancybox({titlePosition: 'inside'});
	
	$('a.videopop').fancybox({titleShow:false});
	
	$('ul.gallery a').fancybox({titlePosition: 'inside'});
	
	$('a.vidOverview').fancybox({titleShow:false});
	*/
	
	$('.compat td:contains("No")').addClass('no');
	$('.links li').normaliseHeight();
	$('.links li').click(function(){
		window.open($('a:eq(0)', this).attr('href'));
		return false;
	});
	$('.news li').click(function(){
		location.href = $('a:eq(0)', this).attr('href');
		return false;
	});
	
	$('ul.subsection').hide().each(function(){
		var list = $(this);
		$(list).prev().click(function(){
			$(this).next().toggle();
		});
	});
	
	// Tab menu controls
	/*
		Recently changed to show only named items, not based on index.
	*/
	
	$('#tabcontainer').each(function(){
		if (location.hash) {
			var ctab = location.hash;
			$('.tabpanel').hide();
			$(ctab).show();
			var i = $('.tabs a').index($('.tabs a[href$='+ctab+']'));
			$('.tabs li:eq('+i+')').addClass('selected');
		} else {
			$('.tabpanel').hide().eq(0).show();
			$('.tabs li:eq(0)').addClass('selected');
		}
	});
	
	$('.tabs a').click(function(){
		var tc = $(this).parent();
		var th = $(this).attr('href');
		$('.tabpanel').hide()
		$(th).show();
		$('.tabs li').removeClass('selected');
		$(tc).addClass('selected');
		return false;
	});

	$('.thickbox').openDOMWindow({ 
		eventType:'click', 
		width:780,
		height:350
	});
	
	$('.popup').each(function(){
		$('fieldset.step', this).slice(1).hide();
	});
	
	$('.errormsg').each(function(){
		$(this).change(function(){
			if($('option:selected', this).val() == 'Yes'){
				$(this).parent().next().show();
			} else {
				$(this).parent().next().hide();
			}
		});
	});
	$('.next a, .prev a').click(function(){
		var fs = $(this).parent().parent().parent().parent();
		$('.step:visible').removeClass('incomplete');
		$('.step:visible .required').removeClass('err');
		$('.step:visible .required').each(function(){
			if($(this).val() == ''){
				$(this).addClass('err');
				$(this).parent().addClass('err');
				$('.step:visible').addClass('incomplete');
			}
		});
		var s = $(this).attr('href');
		if($('.step:visible').hasClass('incomplete')){
			alert('Please complete all required fields');	
		} else {
			$('.step', fs).hide();
			$(s).show();
		}
		return false;
	});
	
	// Support form submit functions
	$('.formSupport').submit(function(){
		//var fs = $(this).parent().parent().parent().parent();
		$('.step:visible').removeClass('incomplete');
		$('.step:visible .required').removeClass('err');
		$('.step:visible .required').each(function(){
			if($(this).val() == ''){
				$(this).addClass('err');
				$(this).parent().addClass('err');
				$('.step:visible').addClass('incomplete');
			}
		});
		//var s = $(this).attr('href');
		if($('.step:visible').hasClass('incomplete')){
			alert('Please complete all required fields');
			return false;	
		} else {
			if($(this).attr('id')=='supportLevel1'){
				if($('.step:visible').attr('id') == 'level1step5'){
					//Assemble subject line
					var d = new Date();
					var uid = d.getDate().toString() + (d.getMonth()+1).toString() + d.getFullYear().toString() + ' / ';
					var platform = $('#level1os option:selected').text().indexOf('Windows') > -1 ? 'W / ' : 'M / ';
					var ver = $('#level1version option:selected').text().replace('Vectorworks ','').replace(' ','');
					var sl = 'L1 / '+ ver + platform + uid + $('#level1subject').val();
					//console.log(sl);
					$('#level1subject').val(sl);
					//console.log($('#subject1').val());
				} else {
					return false;
				}
			}
			
			if($(this).attr('id')=='supportLevel2'){
				if($('.step:visible').attr('id') == 'level2step5'){
					//Assemble subject line
					var d = new Date();
					var uid = d.getDate().toString() + (d.getMonth()+1).toString() + d.getFullYear().toString() + ' / ';
					var platform = $('#os option:selected').text().indexOf('Windows') > -1 ? 'W / ' : 'M / ';
					var ver = $('#version option:selected').text().replace('Vectorworks ','').replace(' ','');
					var sl = 'L2 / '+ ver + platform + uid + $('#level2subject').val();
					//console.log(sl);
					$('#level2subject').val(sl);
				} else {
					return false;
				}
			}
			
		}
	});
	
	
	//Set JS version of Price Request email
	$('#requestQuote #mail_options').val('PlainTemplate=price.txt,AlwaysList,TemplateMissing=');
	//Set JS version of server-side required fields
	$('#requestQuote #required_fields').val('email:Your email address,realname:Your name,licenses');
	
	// Price Request (Quote) form handler
	$('#requestQuote').submit(function(){
		var f = $(this);
		//error checking, zero and blank values
		$(this).removeClass('incomplete');
		//checks text fields
		$('input.required', this).each(function(){
			if($(this).val() == ''){
				$(this).addClass('err');
				$(this).parent().addClass('err');
				$(f).addClass('incomplete');
			}
		});
		//checks drop downs
		$('select.required', this).each(function(){
			if($(this).val() == 0){
				$(this).addClass('err');
				$(f).addClass('incomplete');
			}
		});
		//exit if the form is incomplete
		if($(this).hasClass('incomplete')){
			alert('Please complete all required fields');
			return false;
		} else {
		//assemble data and submit form
			var x=''
			$('.license_options', this).each(function(){
				var q = $('select:eq(1)', this).val();
				var m = $('select:eq(0)', this).val();
				x += q+' x '+m+'\n';
			});
			$('#requestQuote #licenses').text(x);
		}
	});
	
	// Demo Request form handler
	$('#requestDemo').submit(function(){
		var f = $(this);
		//error checking, zero and blank values
		$(this).removeClass('incomplete');
		//checks text fields
		$('input.required', this).each(function(){
			if($(this).val() == ''){
				$(this).addClass('err');
				$(this).parent().addClass('err');
				$(f).addClass('incomplete');
			}
		});
		//checks drop downs
		$('select.required', this).each(function(){
			if($(this).val() == 0){
				$(this).addClass('err');
				$(f).addClass('incomplete');
			}
		});
		//exit if the form is incomplete
		if($(this).hasClass('incomplete')){
			alert('Please complete all required fields');
			return false;
		} else {
		//assemble data and submit form
			$('#requestDemo #company').each(function(){
				if ($(this).val() == ''){
					$('#requestDemo input[name=mail_options]').val('PlainTemplate=dvd_noco.txt,AlwaysList,TemplateMissing=');
				}
			});
		}
	});

	//Remove additional license options
	$('.license_options').slice(1).remove();
	$('.license_clone').show();
	
	$('.module').change(function(){
		if ($('option:selected',this).hasClass('professional')){
			if($(this).next().hasClass('professional')){
				return false;
			} else {
				$(this).next().removeClass('education').addClass('professional').empty().append('<option value="0">Qty</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>');
			}
		} else if ($('option:selected',this).hasClass('education')) {
			if($(this).next().hasClass('education')){
				return false;
			} else {
				$(this).next().removeClass('professional').addClass('education').empty().append('<option value="0">Qty</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="15">15</option><option value="20">20</option><option value="25">25</option><option value="30">30</option><option value="40">40</option><option value="50">50</option>');
			}
		}
	});
	
	$('.windowClose').click(function(){
		$.closeDOMWindow();
	});
	$('.section-layers').each(function(){
		var d = this;
		$('> div', this).hide();
		$('.section-menu a', this).each(function(){
			$(this).click(function(){
				var l = $(this).attr('href');
				$('div', d).hide();
				$(l).fadeIn();
				return false;
			});
		});
	});
	$('.log tbody').each(function(){
		$('tr:even', this).addClass('even');
	});
	
	$('.faq tbody').each(function(){
		$('tr:odd', this).addClass('odd');
	});
	
	$('#courses .navigation a').click(function(){
		$('#courses .course').hide();
		var c = $(this).attr('href');
		$('#courses .navigation li').removeClass('selected');
		$(this).parent().addClass('selected');
		$(c).fadeIn();
		return false;
	});
	
	$('#courses').each(function(){
		if (location.hash) {
			var ctab = location.hash;
			var i = $('.navigation a').index($('.navigation a[href$='+ctab+']'));
			if (i>-1){
				$('.navigation li:eq('+i+')').addClass('selected');
				i++
			}
		} else {
			var i = 0;
		}
		$('.course').hide().eq(i).show();
	});
	
	$('#library .navigation a').click(function(){
		$('#library .videos').hide();
		var c = $(this).attr('href');
		$('#library .navigation li').removeClass('selected');
		$(this).parent().addClass('selected');
		$(c).fadeIn();
		return false;
	});
	
	$('#library').each(function(){
		if (location.hash) {
			var ctab = location.hash;
			var i = $('.navigation a').index($('.navigation a[href$='+ctab+']'));
			if (i==-1){
				i = 0;
			}
		} else {
			var i = 0;
		}
		$('.navigation li:eq('+i+')').addClass('selected');
		$('.videos').hide().eq(i).show();
	});
	
	$('.reviews .review:even').addClass('even-review');
	
	$('.add').click(function(){
		var fs = $(this).parent().parent().parent();
		$(fs).after($(fs).clone(true));
		if($('select:eq(1)', $(fs).next()).hasClass('education')){
			$('select:eq(1)', $(fs).next()).removeClass('education').addClass('professional').empty().append('<option value="0">Qty</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>');
		}
	});
	
	$('.remove').click(function(){
		var fs = $(this).parent().parent().parent();
		var fsl = $('fieldset.license_options').length;
		if(fsl>1){
			$(fs).remove();
		}
	});
	
	$('#frmEval').submit(function(){
		var i = $('select option:selected', this).val();
		if(i==0){
			$('#frmEval').fadeOut(100,function(){
				$('#evaluation').append('<iframe width="100%" height="680" src="http://www.nemetschek.net//trial/form?src=24&t=pro&c=151&l=81&iframe=1"></iframe>');
			});
		}
		if(i==1){
			$('#frmEval').fadeOut(100,function(){
				$('#evaluation').append('<iframe width="100%" height="680" src="http://www.nemetschek.net//trial/form?src=24&t=edu&c=151&l=81&iframe=1"></iframe>');
			});
		}
		if(i==2){
			$('#dialog').dialog('open');
			return false;
		}
		return false;
	});
	
	/*
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Take Me There": function() { 
				top.location.href="/education/tertiary.php"; 
			}
		}
	});
	*/
	
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);

	$('.paypalpurchase').submit(function(){
		var x = $('input[name="os1"]', this).val();
		if (x.length < 6) {
			alert('Please enter the last six characters of your Vectorworks serial number.');
			return false;
		}
	});
	
	$('.vidOverview').click(function(){
		var v = $(this).attr('href');
		$('img', this).hide();
		jwplayer("vidOverview").setup({
	        autostart: true,
	        file: v,
	        flashplayer: "/common/jw/player.swf",
	        volume: 80,
	        width: 450,
	        height: 281
	    });
	    return false;
	});
	
	// 2012 product video triggers
	$('a[href="#new2012"]').click(function(){
		try {
			var v = $('#vidplayer2012').attr('href');
			var m = $('#vidplayer2012 img').attr('src');
			jwplayer("vw2012player").setup({
		        autostart: false,
		        file: v,
		        image: m,
		        flashplayer: "/common/jw/player.swf",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}
	});
	
	// 2011 product video triggers
	$('a[href="#new2011"]').click(function(){
		try {
			var v = $('#vidplayer2011').attr('href');
			var m = $('#vidplayer2011 img').attr('src');
			jwplayer("vw2011player").setup({
		        autostart: false,
		        file: v,
		        image: m,
		        stretching: 'exactfit',
		        flashplayer: "/common/jw/player.swf",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}
	});
	
	// 2012 Designer video triggers
	// Architect
	$('a[href="#newArchitect"]').click(function(){
		try {
			jwplayer("vwArchitect2012player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Architect_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidArchitect.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}		
	});
	// Landmark
	$('a[href="#newLandmark"]').click(function(){
		try {
			jwplayer("vwLandmark2012player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Landmark_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidLandmark.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}		
	});
	// Spotlight
	$('a[href="#newSpotlight"]').click(function(){
		try {
			jwplayer("vwSpotlight2012player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Spotlight_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidSpotlight.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}		
	});
	// Fundamentals
	$('a[href="#newFundamentals"]').click(function(){
		try {
			jwplayer("vwFundamentals2012player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Fundamentals_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidFundamentals.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
	    } catch(err){}		
	});
	
	
	// Fundamentals Overview
	$('#vwFundamentals').each(function(){
		jwplayer("vidOverview").setup({
	        autostart: false,
	        file: 'http://d3gbzdw28d8zd4.cloudfront.net/flv/Fundamentals.flv',
	        flashplayer: "/common/jw/player.swf",
	        image: '/common/images/vidFundamentalsOverview.jpg',
	        stretching: 'exactfit',
	        volume: 80,
	        width: 576,
	        height: 360
	    });
	});
	
	// Designer Overview
	$('#vwDesigner').each(function(){
		jwplayer("vidOverview").setup({
	        autostart: false,
	        file: 'http://d3gbzdw28d8zd4.cloudfront.net/flv/VW_Designer_web.flv',
	        flashplayer: "/common/jw/player.swf",
	        image: "/common/images/vidDesignerOverview.jpg",
	        volume: 80,
	        width: 576,
	        height: 360
	    });
	    jwplayer("vwArchitect2012player").setup({
	        autostart: false,
	        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Architect_2012.mp4',
	        flashplayer: "/common/jw/player.swf",
        	image: "/common/images/vw2012/vidArchitect.jpg",
	        volume: 80,
	        width: 576,
	        height: 290
	    });
	});
	
	
	// VW2012 upgrade functions
	// function to show features based on variable ct
	function showfeatures(ct) {
		$('#newvw2012 .vp').hide();
		$('#newvw2012 .'+ct).show();
		
		if (ct == 'architect'){
			try {
				jwplayer("vw_architect_player").setup({
			        autostart: false,
			        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Architect_2012.mp4',
			        flashplayer: "/common/jw/player.swf",
		        	image: "/common/images/vw2012/vidArchitect.jpg",
			        volume: 80,
			        width: 576,
			        height: 290
			    });
			}
			catch(err){}
		}
		
		if (ct == 'landmark'){
			jwplayer("vw_landmark_player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Landmark_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidLandmark.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
		}
		
		if (ct == 'spotlight'){
			jwplayer("vw_spotlight_player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Spotlight_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidSpotlight.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
		}
		
		if (ct == 'fundamentals'){
			jwplayer("vw_fundamentals_player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Fundamentals_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidFundamentals.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
		}
		
		if (ct == 'renderworks'){
			jwplayer("vw_renderworks_player").setup({
		        autostart: false,
		        file: 'http://d3gbzdw28d8zd4.cloudfront.net/vw2012/Renderworks_2012.mp4',
		        flashplayer: "/common/jw/player.swf",
		        image: "/common/images/vw2012/vidRenderworks.jpg",
		        volume: 80,
		        width: 576,
		        height: 290
		    });
		}
		
		// fixes tab menu
		$('.tabmenu li').removeClass('selected');
		$('.tabmenu a[href$='+ct+']').parent().addClass('selected');
	}
	
	$('#videoloader').each(function(){
		var f = $('.vidref', this).attr('href');
		var p = $('.vidref img', this).attr('src');
		jwplayer("player").setup({
	        autostart: false,
	        file: f,
	        image: p,
	        flashplayer: "/common/jw/player.swf",
	        volume: 80,
	        width: 800,
	        height: 500
	    });
	});
	
	$('#newvw2012 .caption').hide();
	$('#newvw2012 .tabfeatures li').hide();
	
	var u = top.location.href;
	if (u.indexOf('#') > 0){
		var ct = u.slice(u.indexOf('#')+1);
	} else {
		var ct = 'architect';
	}
	showfeatures(ct);
	
	$('.tabmenu a').click(function(){
		// get current tab
		var ct = $(this).attr('href').slice(1);
		
		//hide all video captions and features, empyty fp
		$('#newvw2012 .caption').hide();
		$('#newvw2012 .tabfeatures li').hide();
		$('.vp').hide();
		
		// show based on tab selection
		showfeatures(ct);
	});
	
	$('.studies').each(function(){
		$('li', this).normaliseHeight();
	});
});

