document.documentElement.className = 'js';
Cufon.replace('.feature h2, #heading', {
	textShadow: '#145028 1px 1px'
});
Cufon.replace('.products#anchors a,.main h2, #main h2,h3,h4,legend span');
Cufon.replace('.products .main h2, .products h3 b', { fontFamily: 'scenestd-black' });
Cufon.replace('.products h3 .subt');
$(function(){
	
	var n = navigator.userAgent;
	var win = n.indexOf('Windows') > -1;
	var mac = n.indexOf('Macintosh') > -1;
	var ff = n.indexOf('Firefox') > -1;
	var ie = n.indexOf('MSIE') > -1;
	var safari = n.indexOf('Safari') > -1 && n.indexOf('Chrome') == -1;
	var chrome = n.indexOf('Chrome') > -1; 
	var c = $('body').attr('class');
	if( win ) c = c != '' ?  c + ' win' : 'win';
	if( mac || safari ) c = c != '' ?  c + ' mac' : 'mac';
	if( ff ) c = c != '' ?  c + ' ff' : 'ff';
	if( ie ) c = c != '' ?  c + ' ie' : 'ie';
	if( chrome ) c = c != '' ?  c + ' chrome' : 'chrome';
	$('body').addClass(c);
	var ie = $.browser.msie;
	if ( ie ) {	
		$('li:first').addClass('first');
		$('li:last-child').addClass('last');
	}
	
	$('li:last-child').addClass('last');
	
	var loc = top.location.toString();
	loc = loc.substr(0, loc.length - 1);
	loc = loc.indexOf('#') != -1 ? loc.substr(0,loc.indexOf('#') - 1) : loc;
	locRel = loc.substr(loc.lastIndexOf('/') + 1);
	locRel2 = loc.substr( 0,loc.lastIndexOf('/') );
	locRel2 = locRel2.substr( locRel2.lastIndexOf('/') + 1 );
	
	var h = top.location.host.toString();
	var href = top.location.href;
	var i = href.indexOf(h) + h.length + 1;
	var pre = href.substr( i );

//	console.log ( 'locRel: ' + locRel );
//	console.log ( 'locRel2: ' + locRel2 );
	
	$('#menu a').filter(function(){
		if ( locRel === 'public_html' || locRel === 'aw' || locRel === '') locRel = 'null';
		if ( locRel2 === 'public_html' || locRel2 === 'aw' || locRel2 === '') locRel2 = 'null';
		if ( $(this).attr('href').indexOf('/' + locRel) != -1 || $(this).attr('href').indexOf('/' + locRel2) != -1 ){
			if ($(this).is(':contains("Security")')) {
				//if ( locRel === 'privacy-and-security' ) return true;
				return false;
			}
			return $(this)
		}
		 
		
	}).parent().addClass('sel');
	
	$('#head .button, #main .button, #key-features li img').each(function(){
		if ( ie && $(this).is('.feature-list.intro .button') ) return;
		$(this).wrap('<span class="button-wrap"></span>');
	});
	$('.button-wrap').each(function(){
		var w = $(this).width();
		if ( w > 80 ) $(this).addClass('button-wrap-wide');
	});
	
	$('.scroll').each(function(){
		var t = $(this);
		var el = t.find('li');
		var keyFeatures = t.parents('#key-features').length > 0;
		var cate = keyFeatures ? 3 : 1;
		if ( el.length <= cate ) return;
		t.parent().addClass('scrollable');
		if ( keyFeatures )
			t.parent().prepend('<a class="scroll-nav nav-left" href=# title="show previous features">&laquo;</a>').append('<a class="scroll-nav nav-right" href=# title="show more features">&raquo;</a>');
		else t.parent().append('<a class="scroll-nav nav-left" href=#>«</a><a class="scroll-nav nav-right" href=#>»</a>');
		t.scrollable ({
			size:cate, 
			clickable:false, 
			nextPage:'.nav-right', 
			prevPage:'.nav-left'
		});
	});
	
	$('.scroll-nav').click(function(e){
		e.preventDefault();
	});
	
	$('#nav .extra').each(function(){
		var t = $(this);
		t.hide().css('minHeight',0);
		var m = $('#main').outerHeight();
		var n = $('#nav').outerHeight(); 
		if ( m > n ) t.height( m - n ).show();
	});
	
	$('.eq-col').each(function(){
		var max = 0, h = 0, t = $(this);
		var col = t.find('.col');
		col.each(function(){
			h = $(this).height();
			if ( h > max ) max = h;
		});
		if ( max ) col.height(max);
	});
	
	if ( $('#page-key-features').length > 0 && typeof($.fn.colorbox) != 'undefined' ) {
		$.fn.colorbox.init();
		$("#page-key-features .thumbs a[rel]").colorbox({
			onComplete: function(){
				var c = $('#cboxTitle');
				Cufon.replace(c);
			}
		});
	}

	$('#cboxNext, #cboxPrevious').live('hover',function(){
		var t = $(this);
		if ( t.is('#cboxPrevious') )
			t.animate({'left':-87}, 'fast')
		else
			t.animate({'right':-87}, 'fast')
	}).live('mouseout',function(){
		var t = $(this);
		if ( t.is('#cboxPrevious') )
			t.animate({'left':-29}, 'fast')
		else
			t.animate({'right':-29}, 'fast')
	});
	
	if ( $('#contact-form').length ) {
		var t = $('#contact-form');
		if ( ie ) {
			t.find('button').click(function(){
				t.submit();
			});
		}
		t.ketchup();
	}
	
	$('.fields label input, .fields label textarea, .fields label select').focus(function(){
		$(this).parent().addClass('h').parents('ul:first').addClass('h');
	}).blur(function(){
		$(this).parent().removeClass('h').parents('ul').removeClass('h');
	});

	var showMap = function(){
		var l = $('#location');
		if ( !l.length ) return;
		l.append('<div id="map"></div>');
		var myLatlng = new google.maps.LatLng(37.90107,-122.061374);
		var myOptions = {
		  zoom: 16,
		  center: myLatlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map(document.getElementById("map"), myOptions);
		var geocoder = new google.maps.Geocoder();
		var address = $('address').text().replace(/\n/g,'').replace(/\r/g,'');
		if (geocoder) {
		  geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
			  map.setCenter(results[0].geometry.location);
			  var marker = new google.maps.Marker({
				  map: map, 
				  position: results[0].geometry.location
			  });
			} else {
			  alert("Geocode was not successful for the following reason: " + status);
			}
		  });
		  
		}
	}();
	
	$('.products .main .feature-list li').each(function(){
		var t = $(this);
		var arePoze = t.find('.s').length;
		if ( !arePoze ) t.css('padding-right',67);
	});
	
	$('#popuplink a').click(function(e){
		if ( typeof($.fn.colorbox) == 'undefined' ) return;
		var t = $(this);
		var url = t.attr('href');
		var title = t.text();

		/*var i = $(this).parent().index();
		var id = 'm' + i;
		$('<div class="modal"></div>').appendTo('body').attr( 'id', id + '>.main' ).load(href + ' .main', function(){
		
			$.fn.colorbox({ inline:true, href:id });
			
		});*/
		$.fn.colorbox({
			href: url + ' .main', 
			title: title, 
			onComplete: function(){
				var c = $('#cboxTitle');
				var h = $('#colorbox h2, #colorbox h3, #colorbox h4')
				Cufon.replace(c);
				Cufon.replace(h);
			}
		});
		e.preventDefault();
	});
	
	
});