var prodDetailsExpand = 185;
var prodDetailsCollapse = 310;
var prodDetailsBase = 165;
var prodDetailsPadding = 40;
var colorState = 'off';
$(document).ready(function() {
	
	$('span[style="text-decoration: line-through;"]').each(function(){
		$(this).addClass('strike');
		$(this).attr('style','');
	});
	
	try{
		$("input.phonenumber").mask("(999) 999-9999");
	    $("input.state").mask("aa");
    	$("input.zipcode").mask("99999");
	    $("input.qtymask").mask("9");
	}catch(err){}
	//try{$('#rightspacer').height($('#bodycopysurround').height() - $('#rightcopysurround').height() - 75);}catch(err){}
	try{$('#rightspacer').height($('#bodycopysurround').height() - $('#rightcopysurround').height() + 25);}catch(err){}
	
	$('#projectinfo').click(function(){
		
	});
	try{
		$('#homeimage_one_container').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 4000, 
			pause: 1
		});
		$('#homeimage_two_container').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 8000, 
			pause: 1
		});
		$('#homeimage_three_container').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 6000, 
			pause: 1
		});
	}catch(err){}
	
	try{
		$('#slides').cycle({ 
			fx:     'fade', 
			speed:  1000, 
			timeout: 8000, 
			pause: 1,
			pauseOnPagerHover: 1,
			pager:  '#imgnav' 
		});
		if($('#slides li').length == 1){
			$('#slides').attr('style','position: relative; width: 600px; height: 320px;');
			$('#slides li:first').attr('style','position: absolute; top: 0px; left: 0px; display: block; z-index: 5; opacity: 1;');
		}
		
		if($('#slides li[rel=before]').length>0){
			$('#imgnav a:last').addClass('before').html('Before');
		}
		
		var oDescHeight = 0;
		if($('li.first').height() + prodDetailsPadding > $('li.second').height() + prodDetailsPadding){
			oDescHeight = $('li.first').height() + prodDetailsPadding;
		}else{
			oDescHeight = $('li.second').height() + prodDetailsPadding;
		}
		
		prodDetailsExpand = prodDetailsCollapse - oDescHeight;
		$('#projectdetails_back').css('height',oDescHeight);
		
		
		$('#slides li').each(function(id){
			var oXpos = $(this).attr('xpos').split(',');
			var oYpos = $(this).attr('ypos').split(',');
			var oText = $(this).attr('text').split(',');
			if(oXpos.length > 0 && oYpos.length > 0 && oText.length > 0 && oXpos[0]!= "" && oYpos[0]!="" && oText[0]!=""){
				for(var i = 0;i<oXpos.length;i++){
					$(this).append('<a href="javascript:;" class="project_button" style="margin-left:'+oXpos[i]+'px;margin-top:'+oYpos[i]+'px;" title="'+oText[i]+'"><span></span></a>');
				}
			}
		},SetToolTips());
	}catch(err){}
	
	try{
		$('#taglineul').cycle({ 
			fx:     'fade', 
			speed:  2000, 
			timeout: 8000, 
			pause: 0
		});
	}catch(err){}

	$("#projectinfo").toggle(
		function () {
			$('#projectdetails').animate({
				marginTop: prodDetailsExpand
			},500);
			$(this).text('- PROJECT STORY');
		}, 
		function () {
			$('#projectdetails').animate({
				marginTop: prodDetailsCollapse
			},500);
			$(this).text('+ PROJECT STORY');
		}
	);
	
	DoProjectButtonColors();
	
});
function DoProjectButtonColors(){
	var adjustedHigh = (parseFloat(5000) - parseFloat(2000)) + 1;
	var numRand = 0;
	$("a.project_button").each(function(id){
        numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(1000);
		$(this).mouseover(function(){
			$(this).attr('pbutton_state','on').addClass('selected');
			$(this).children('span').css('backgroundColor','#ffffff');
		});
		$(this).mouseout(function(){
			$(this).attr('pbutton_state','off').removeClass('selected');
			$(this).children('span').css('backgroundColor','#38161D');
		});
		$(this).attr('rel',numRand);
		DoProjectButton($(this));
	});
}
function DoProjectButton(oElem){
	setTimeout(function(){
		if(oElem.attr('pbutton_state') != 'on'){
			oElem.children('span').animate({ backgroundColor: "#ffffff" }, 2500).animate({ backgroundColor: "#38161D" }, 2500);
		}
		DoProjectButton(oElem);
	}, parseInt(oElem.attr('rel')));
}

function SetToolTips(){
	setTimeout(function() {
		$("a.project_button").tooltip({tooltipClass: 'project_tips',opacity:75});
	}, 1000);
}
function DoMapContent(oMap, oLattitude, oLongitude, oFriendlyPopup) {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById('' + oMap + ''));
        var marker = new GMarker(new GLatLng(oLattitude, oLongitude));
			'' + oFriendlyPopup + '' +
			'</div>';

        map.setCenter(new GLatLng(oLattitude, oLongitude), 13);
        map.addControl(new GSmallMapControl());
        map.addOverlay(marker);
		
		var html = '<div style="width:175px; padding-right:10px;">' +
			'' + oFriendlyPopup + '' +
			'</div>';
		marker.openInfoWindowHtml(html);
    } else {
    }
}

jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}
