<?php
	require_once( $_SERVER['DOCUMENT_ROOT'] . '/res/settings/settings.php' );
?>
var xmlFile = "/res/actions/get_rand_images.php";
var lgPath = "lgPath=/lib/galleries/general/lg";
var tnPath = "tnPath=/lib/galleries/general/tn";
//
var project_xmlFile = "/res/actions/get_rand_images.php";
var project_lgPath = "lgPath=/lib/galleries/general/lg";
var project_tnPath = "tnPath=/lib/galleries/general/tn";

var Site = {
	
	pageDomReady: function() {
		Site.blurAllLinks();
		Site.preloadImages('/lib/slideshow/loader-1.png','/lib/slideshow/loader-2.png','/lib/slideshow/loader-3.png','/lib/slideshow/loader-4.png','/lib/slideshow/loader-5.png','/lib/slideshow/loader-6.png','/lib/slideshow/loader-7.png','/lib/slideshow/loader-8.png','/lib/slideshow/loader-9.png','/lib/slideshow/loader-10.png','/lib/slideshow/loader-11.png','/lib/slideshow/loader-12.png');
	},
	pageLoaded: function () {
		Site.loadHomepageSound();
	},
	preloadImages: function () {
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=Site.preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	},
	scrollCheck: function() {
		if ( $('scrollsTo') && $('scrollsTo').value ) Site.scrollsTo($('scrollsTo').value);
	},
	openWindow: function(winUrl,winName,winOptions) {
		return window.open(winUrl,winName,winOptions);
	},
	blurAllLinks: function() {
		$$('a').each(function(aLink) {
			aLink.addEvent('focus', function(){ aLink.blur(); });
		});
	},
	scrollsTo: function( pageAnchor ) {
		anchorScroll.toElement($(pageAnchor));
		 return false;
	},
	loadHomepageSound: function() {
		if ($('homepage_sound')) {
			flashObj = new SWFObject("/lib/swf/music_player.swf", "home_page_sound_obj", "1", "1", 9, "#F9F8FD", true);
			flashObj.addParam("wmode", "transparent");
			flashObj.addParam("salign", "tl");
			flashObj.addVariable("soundFile", "/lib/mp3/homepage.mp3");
			flashObj.write("homepage_sound");
		}
	},
	loadProjectPhotos: function() {
		if ($('project_info_col_1')) {
			flashHeaderObj = new SWFObject("/lib/swf/property_images.swf", "page_header_right_photos", "450", "345", 9, "#F9F8FD", true);
			flashHeaderObj.addParam("wmode", "transparent");
			flashHeaderObj.addParam("salign", "tl");
			flashHeaderObj.addParam("scale", "noscale");
			flashHeaderObj.addVariable("xmlFile", project_xmlFile);
			flashHeaderObj.addVariable("lgPath", project_lgPath);
			flashHeaderObj.addVariable("tnPath", project_tnPath);
			flashHeaderObj.addVariable("project_id", project_id);
			flashHeaderObj.write("project_info_col_1");
		}
	},
	changeProjectPhoto: function(url) {
		if ( $('project_image') ) {
			$('project_image').setProperty('src', url);
		}
	},
	setupAjaxNews: function() {
		if ( $('news_article_wrapper') ) {
			var url = "/res/actions/get_rss_news.php";
			new Ajax(url, {
				method: 'get',
				update: $('news_article_wrapper'),
				onComplete: function() { setTimeout (Site.setupNewsArticlesScroll, 10000); }
			}).request();
		}
	},
	removeTeamPhoto: function(user_id) {
		if ( confirm("Are you sure you want to delete this photo?") ) {
			var url = "/res/actions/ajax/remove_team_photo.php?user_id="+user_id;
			$('team_photo_'+user_id).setProperty('src','http://<?php echo $DATA_HOST[$SERVER] ?>/lib/team_photos/no_image.jpg');
			new Ajax(url, {
				method: 'get',
				update: $('team_update_status'),
				onComplete: function() { 
					$$('.team_edit_images').each(function(img) {
						$(img).setProperty('src',$(img).getProperty('src'));
					});
				}
			}).request();
		}
	},
	removeInsightPhoto: function(insight_id) {
		if ( confirm("Are you sure you want to delete this photo?") ) {
			var url = "/res/actions/ajax/remove_insight_photo.php?insight_id="+insight_id;
			$('insight_photo_'+insight_id).setProperty('src','');
			new Ajax(url, {
				method: 'get',
				update: $('insight_update_status'),
				onComplete: function() { 
					$$('.team_edit_images').each(function(img) {
						$(img).setProperty('src',$(img).getProperty('src'));
					});
				}
			}).request();
		}
	},
	validateContactForm: function() {
		var error_found = false;
		var error_message = '';
		if ( !$('contact_name').value ) {
			error_found = true;
			error_message += "\nName is Required.";
		}
		if ( !$('contact_email').value ) {
			error_found = true;
			error_message += "\nEmail is Required.";
		}
		if ( !$('contact_validation').value ) {
			error_found = true;
			error_message += "\nValidation Code is Required.";
		}
		
		if ( error_found ) {
			alert(error_message);
		} else {
			$('frmContact').submit();
		}
	},
	removeUser: function(id) {
		if ( confirm("Are you sure you want to delete this user?") ) {
			var col_1 = $(id+"_team_col_1");
			var col_2 = $(id+"_team_col_2");
			var mce   = $(id+"_user_info_container");
			var myFx = new Fx.Style(col_1, 'opacity').start(1,0);
			var myFx2 = new Fx.Style(col_2, 'opacity').start(1,0);
			var myFx3 = new Fx.Style(mce, 'opacity').start(1,0);
			$(id+"_deleted").setProperty('value',1);
		}
	},
	removeInsight: function(id) {
		if ( confirm("Are you sure you want to delete this insight?") ) {
			var col_1 = $(id+"_insights_col_1");
			var col_2 = $(id+"_insights_col_2");
			var mce   = $(id+"_insight_title");
			var mce2   = $(id+"_insight_text");
			var myFx = new Fx.Style(col_1, 'opacity').start(1,0);
			var myFx2 = new Fx.Style(col_2, 'opacity').start(1,0);
			var myFx3 = new Fx.Style(mce, 'opacity').start(1,0);
			var myFx4 = new Fx.Style(mce2, 'opacity').start(1,0);
			$(id+"_deleted").setProperty('value',1);
		}
	},
	teamUpdateStatus: function(msg) {
		$('team_update_status').setHTML(msg);
		$$('.team_edit_images').each(function(img) {
			$(img).setProperty('src',$(img).getProperty('src'));
		});
	},
	teamNewStatus: function(msg) {
		$('team_new_status').setHTML(msg);
	},
	insightUpdateStatus: function(msg) {
		$('insight_update_status').setHTML(msg);
		$$('.insight_edit_images').each(function(img) {
			$(img).setProperty('src',$(img).getProperty('src'));
		});
	},
	insightNewStatus: function(msg) {
		$('insight_new_status').setHTML(msg);
	}
}
window.addEvent('domready', Site.pageDomReady);
window.addEvent('load', Site.pageLoaded);