var dGreenWork, dGreenWorkA, dGreenProduct, dGreenProductA;
var cGreenProduct, cGreenProductUL, cGreenProductA;
var cGreenHome, cGreenHomeA,dGreenWorkDiv;
var dGreenBuilder, dGreenBuilderA, dGreenBuilderUL;
var dialog = null;
$(document)
.ready(function(){
	var theContentbox = $('#theContentbox');
	var l = theContentbox.css('left');
	var t = theContentbox.css('top');
	var r = theContentbox.css('right');
	var b = theContentbox.css('bottom');
	var w = theContentbox.css('width');
	
	theContentbox.jScrollPane({showArrows:true,scrollbarWidth:5, scrollbarMargin:5});//}
	
	theContentbox.css({left:0,right:0,top:0,bottom:0})
	
	$('.jScrollPaneContainer').css({left:l,top:t})

	$('.logoimage,.logoimagegreen, img[src*=leaf]')
	.css({cursor:'pointer'})
	.click(function(){
		var el = $(this);
		var title = el.attr('alt');
		if (typeof title == 'undefined' ){
			title = '';
		};
		if( el.is('img') ){
			var content = '<p>Great new product coming soon</p>';
			el.removeAttr('title');
		}
		else{
			var content = '<p>'+el.attr('title').replace(/\/n\/n/,'<br><br>')+'</p>';
			content += '<p><a href="'+el.attr('href')+'" target="_blank">'+el.attr('href')+'</a></p>';
		};
		$.modal('<div class="titleBar">'+title+'</div><div class="content">'+content+'</div>', {
			containerId : 'productContainer',
			close : true,
			overlay : 0,
			closeTitle : 'Close',
			closeClass : 'titleBar-close',
			onOpen : function(dialog){
				dialog.overlay.remove();
				dialog.container.css('position','absolute').show();
				dialog.data.show();
			}
		});
		return false;
	});
	
	if($.browser.safari ){
		$('#fixText').css('font-size','1.2em');
	};
	
	/*
	.click(function(){
		if( dialog ){
			dialog.dialog('destroy');
		};
		dialog = $('<div>').appendTo('body');
		dialog.dialog({
			title : el.attr('alt'),
			width:500,
			height:350,
			resizable:false,
			open : function(){
				$('.ui-resizable-handle').remove();	
				var el = $(this);
				el.removeAttr('style');
				$('.ui-dialog').css('overflow-x','visible');
				$('.ui-dialog').css('overflow-y','visible');
			}
		});
		return false;
	});
	*/
	
	dGreenBuilder = $('#dGreenBuilder');
	dGreenBuilderA = dGreenBuilder.find('a:first');
	dGreenBuilderUL = dGreenBuilder.children('ul');
	
	dGreenBuilderA
	.toggle(
		function(){
			if( dGreenBuilderUL.hasClass('active') ){
				dGreenBuilderA.click();
			}
			else{
				dGreenBuilderUL.stop().animate({width:190},700,function(){dGreenBuilderUL.addClass('active');dGreenBuilderA.addClass('active');});
	
				if( dGreenProductUL.hasClass('active') ){
					dGreenProductA.click();
				};
	
				if( dGreenWork.hasClass('open') ){	
					dGreenWorkA.click();
				};
			};
		},
		function(){
			dGreenBuilderUL.stop().animate({width:0},700,function(){dGreenBuilderUL.removeClass('active');dGreenBuilderA.removeClass('active');});
		}
	);
	
	dGreenProduct = $('#dGreenProduct');
	dGreenProductA = $('#dGreenProduct').find('a:first');
	dGreenProductUL = dGreenProduct.children('ul');
	
	dGreenProductA
	.toggle(
		function(){
			if( dGreenProductUL.hasClass('active') ){
				dGreenProductA.click();
			}
			else{
				dGreenProductUL.stop().animate({width:165},700,function(){dGreenProductUL.addClass('active');dGreenProductA.addClass('active');});
	
				if( dGreenWork.hasClass('open') ){	
					dGreenWorkA.click();
				};
	
				if( dGreenBuilderUL.hasClass('active') ){
					dGreenBuilderA.click();
				};
			};
		},
		function(){
			dGreenProductUL.stop().animate({width:0},700,function(){dGreenProductUL.removeClass('active');dGreenProductA.removeClass('active');});
		}
	);

	dGreenWork = $('#dGreenWork');
	dGreenWorkA = $('#dGreenWork').find('a:first');
	dGreenWorkDiv = $('#dGreenWork').find('div:first');

	dGreenWorkA
	.toggle(
		function(){
			if( dGreenWork.hasClass('open') ){	
				dGreenWorkA.click();
			}
			else{
				dGreenWorkDiv.stop().animate({width:165},700,function(){dGreenWork.addClass('open');dGreenWorkA.addClass('active');});
	
				if( dGreenProductUL.hasClass('active') ){
					dGreenProductA.click();
				};
	
				if( dGreenBuilderUL.hasClass('active') ){
					dGreenBuilderA.click();
				};
			};
		},
		function(){
			dGreenWorkDiv.stop().animate({width:0},700,function(){dGreenWork.removeClass('open');dGreenWorkA.removeClass('active');});	
		}
	);

	cGreenProduct = $('#cGreenProduct');
	cGreenProductUL = cGreenProduct.children('ul');
	cGreenProductA = cGreenProduct.find('a:first');
	
	cGreenProductA
	.toggle(
		function(){
			if( cGreenProductUL.hasClass('active') || cGreenProductUL.hasClass('opened') ){
				cGreenProductA.click();			
			}
			else{
				cGreenProductUL.stop()
				.animate({width:165},700,function(){
											cGreenProductUL.addClass('active');
											cGreenProductA.addClass('active');
										});
	
				if( cGreenHome.hasClass('open') ){
					cGreenHomeA.click();			
				};
				cGreenProductUL.addClass('opened');
			};
		},
		function(){
			cGreenProductUL.stop()
			.animate({width:0},700,function(){
										cGreenProductUL.removeClass('active');
										cGreenProductA.removeClass('active');
									});
			cGreenProductUL.removeClass('opened');
		}
	);

	cGreenHome = $('#cGreenHome');
	cGreenHomeDiv = $('#cGreenHome').find('div:first');
	cGreenHomeA = $('#cGreenHome').find('a:first');

	cGreenHomeA
	.toggle(
		function(){
			if( cGreenHome.hasClass('open') || cGreenHome.hasClass('opened') ){
				cGreenHomeA.click();			
			}
			else{
				cGreenHomeDiv.stop()
				.animate({width:165},700,function(){
											cGreenHome.addClass('open');
											cGreenHomeA.addClass('active');
										});
	
				if( cGreenProductUL.hasClass('active') ){
					cGreenProductA.click();			
				};
				cGreenHome.addClass('opened');
			};
		},
		function(){
			cGreenHomeDiv.stop().animate({width:0},700,function(){cGreenHome.removeClass('open');cGreenHomeA.removeClass('active');});
			cGreenHome.removeClass('opened');
		}
	);
	
	$('#interActive')
	.click(function(){
		$.modal('<div></div>',{persist: true,onOpen: function(dialog){
			dialog.overlay.fadeIn();
			dialog.container.fadeIn();
			dialog.data.show().html(flash);
		}})
		return false;
	});
	
	$('a.extralink')
	.unbind('click')
	.click(function(e){
		e.preventDefault();
		$.modal('<div></div>',{persist: true,onOpen: function(dialog){
			dialog.overlay.fadeIn();
			dialog.container.fadeIn();
			dialog.data.show().html(flash2);
		}})
		return false;
	});
	
$.ifixpng('http://green.twperry.com/wp-content/themes/twperry/common/img/pixel.gif'); 
$('img[@src$=.png]').ifixpng();
	
});

var flash = '<iframe name="flash" src="/INTERACTIVE_HOUSE/interactive.html" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no"></iframe>';

var flash2 = '<iframe name="flash" src="/flash/classic/presentation.html" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no"></iframe>';