$(document).ready(function() {
	$('#tabs a').addClass('links');
	if($.browser.msie){
		  $("a.links").mbFlipText(true).css({
			  'width': '29px',
			  'line-height': '29px',
			  'letter-spacing':'-0.05em'
			  }).children('span').css({
					'height':'152px',
					'width':'29px'
			  });
					  
			$('#nav > li > a').hover().css('behavior','url(/PIE.htc)');
			$('#nav > li > ul').css({
			'behavior':'url(/PIE.htc)',
			'background-color':'#ffffff'
			});			
			
			if($.browser.version > 7.0){
			$('#how-we-build #rotate .copy-box').css({
			'behavior':'url(/PIE.htc)',
			'background-color':'#ffffff'
			});
				}else{
					$('article#ads-container').css('margin-left','45px');
					}
		}else{
			$('head').append('<link href="/css/not-ie.css" rel="stylesheet" type="text/css">');
			};
		
	var thepath = $.url.attr("path");
	var seg = $.url.segment(0);
	var secseg = $.url.segment(1);
	if(thepath){
		$('#tabs a').each(function(){
			var href = $(this).attr('href');
			if(href == thepath){
				$(this).wrap('<div />');
				}else if(seg == "blog"){
					$(this).wrap('<div class="active" />');
				}else if(seg != 'commercial' && href == '/homes-cabins/index.html'){
					$(this).wrap('<div />');
				}else if(href.indexOf('/'+seg+'') == 0){
					$(this).wrap('<div />');
				}else{
					$(this).wrap('<div class="active" />');
					};
			});
	};
	
	$('#nav > li > ul').width(function(){
		var thiswidth = $(this).width();
		var thatwidth = $(this).parent().width();
		if(thiswidth < thatwidth){
		return $(this).parent().width();
		};
	});
	
	$('#nav > li > ul').hover(function(){
    $(this).parent().children('a').toggleClass("over");
	});
	
	$('#nav > li a').each(function(){
		var thislink = $(this).attr('href');
		if(thislink.indexOf('/'+seg+'/'+secseg) == 0 || thislink.indexOf(secseg) == 13 || thislink.indexOf(secseg) == 11){
			$(this).addClass('sec');
			}		
		});
	
		$("#nav > li > a").addClass(function(index, currentClass){
			var addedClass = '';
			if($(this).siblings().length == 1){
				addedClass = 'main';
				}
				return addedClass;
		});

	$("#nav > li > a").bind("touchstart", function(e){
		if($(this).hasClass('main')){
			e.preventDefault();
			$(this).removeClass('main');
		}
		
		$(this).next('ul').toggleClass("mobile");
		});
		
	$("#modal-boxes a.project").each(function(){
		var thehref = $(this).attr('href');
		$(this).attr({
  			href: thehref+'?iframe=true&width=812&height=100%',
  			rel: 'prettyPhoto[iframe]',
			title:'Project'
			});
		});	

	
	$("#searchform #s").after('<span></span>');
	
  }); 
