$(document).ready(function(){



});


function carousel_callback(carousel) {

	$('#next').bind('click', function() {

			if ( $('#carousel a').hasClass("selected") )
			{			

				if($('#carousel').find('a.selected').parent().is(":last-child"))
				{
					carousel.scroll(1);
					$('#carousel').find('a.selected').removeClass("selected");
					$('#carousel').find("li:first-child").find('a').trigger('click').addClass("selected");					
					
				} else {

					carousel.next();
					$('#carousel').find('a.selected').removeClass("selected").parent().next('li').find('a').trigger('click').addClass("selected");
				}

			} else {
				
				$('#carousel').find('li:eq(0) a').trigger('click').addClass("selected");
			
			}
        
        
			return false;
        
	});



	$('#prev').bind('click', function() {


			if ( $('#carousel a').hasClass("selected") )
			{			

				if($('#carousel').find('a.selected').parent().is(":first-child"))
				{
					//alert($('#carousel li').size());
					carousel.scroll($('#carousel li').size());
					$('#carousel').find('a.selected').removeClass("selected");
					$('#carousel').find("li:last-child").find('a').trigger('click').addClass("selected");					
					
				} else {

					carousel.prev();
					$('#carousel').find('a.selected').removeClass("selected").parent().prev('li').find('a').trigger('click').addClass("selected");
				}

			} else {
				carousel.scroll($('#carousel li').size());
				$('#carousel').find("li:last-child").find('a').trigger('click').addClass("selected");
			
			}
        
        
			return false;
        
	});



}





var swfId = "flash";
var swfFriendly = false;

function openWindow(pageUrl) {
	var winName = Math.round(9999*Math.random()) + new Date().getTime();
	var winNew = window.open(pageUrl,winName,"toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=420,height=300,left=100,top=100");

	if(!winNew) {
		getSwf(swfId).openWindowFromSwf(pageUrl);
	} else {
		winNew.focus();
	}
}


function getSwf(id) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[id];
	} else {
		return document[id];
	}
}    





function addProject() {
	var projectid = document.getElementById("numProjects").value;
	
	$.get('/inc/pages/projectitem.php?i=' + projectid,
			function(data) {
				$('#newProject').append(data);
			}
	);

	projectid = (projectid - 1) + 2;
	document.getElementById("numProjects").value = projectid;
}


function removeProject(itemid) {
	$(itemid).remove();
}

function removeNote(noteid) {
	$(noteid).remove();
}


function moreNotes() {
	var notesid = document.getElementById("notesid").value;
	
	$.get('/inc/pages/jobnotes.php?i=' + notesid,
			function(data) {
				$('#moreNotes').append(data);
			}
	);

	notesid = (notesid - 1) + 2;
	document.getElementById("notesid").value = notesid;
}



function loadFlash(pagename) {

	if (swfobject.hasFlashPlayerVersion("9.0.0")) {
		swfobject.createCSS("#wrapper", "display:none;");
		swfFriendly = true;
	}

	var flash_vars = { pagename: pagename };
	var params = { wmode: "opaque" };
	var attributes = { id: "flash" };

	swfobject.embedSWF("/swf/fdg_global.swf?iesux=" + new Date().getTime(), "flash", "100%", "100%", "9.0.0", "false", flash_vars, params, attributes);

}




function googleMap2() {
	var mapWin = window.open("googlemap.php","Google Map","height=440,width=560,directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes");
	mapWin.focus();	
}



function googleMap() {

	if (swfFriendly == true) {
		// load google map swf
		getSwf(swfId).loadGoogleMap();
		
	} else {
		// old skool html google map
		$('#googlemap').html('<iframe src="/googlemap.php" id="mapframe" frameborder="0" scrolling="no"></iframe>');
		$('#mapframe').css('display','block');
	
	}

}



function closeMap() {
	var iframe = document.getElementById('mapframe');
	iframe.parentNode.removeChild(iframe);
}


function addFlash(flashfile,divid,extra) {
	document.getElementById(divid).innerHTML = "<embed style='width: 100%; height: 100%;' type='application/x-shockwave-flash' src='flash/" + flashfile + "' quality='high' wmode='transparent'></embed>";
}



function oldaddFlash(flashfile,divid,extra) {
	document.getElementById(divid).innerHTML = "<object type='application/x-shockwave-flash' data='flash/" + flashfile + "' width='100%' height='100%' /><param name='movie' value='flash/" + flashfile + "' /><param name='menu' value='false' /><param name='quality' value='high' />" + extra + "</object>";
}

