var timer;
var timer2;


$(function(){

//	$('#submenu').slideUp();
	$('#submenu').hide();


	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	$.localScroll.defaults.axis = 'xy';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#scroll_container', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	$.localScroll({
		target: '#scroll_container', // could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
//			$('.navarrow').hide();
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
//			pauseAllMovies();
//			$('.navarrow').show();
		}
	});

	var sumwidth = 0;

	$(".sliding_block").each(function(){
		sumwidth += ( $(this).width() + 150 );
	});

	sumwidth = sumwidth + 50;

	$('#scroll_wrap').css("width",sumwidth+"px");
//	alert($('#scroll_wrap').css("width"));

//	timer =  setInterval("checkPage()",1000);

	var logotimer;
	logotimer =  setInterval("rotatelogo()",2000);


$('.moremedia').masonry({
  itemSelector: '.media_element'
});




});
	var logocounter = 1;

	var logo_strings = new Array();

	logo_strings[1]	= 'Wired.';
	logo_strings[2]	= 'Networked.';
	logo_strings[3]	= 'Connected.';
	logo_strings[4]	= 'Experience.';

	function rotatelogo(){
		if(logocounter < 5) {
			$('.logo_line2').html(logo_strings[logocounter]);
			logocounter++;		
		}
		else {
			logocounter = 1;
			$('.logo_line2').html(logo_strings[logocounter]);
			logocounter++;		
		}
	}


function getRequestBody(oForm) { 
     var aParams = new Array();
     for(var i = 0; i < oForm.elements.length; i++) {
         var sParam = encodeURIComponent(oForm.elements[i].name);
         sParam += "=";
         sParam += encodeURIComponent(oForm.elements[i].value);
         aParams.push(sParam);
     }
     return aParams.join("&");
 }

function resetForm(formid){
document.getElementById(formid).reset();
}




 function getformpost(script,form) {
         
         var nameRequestForm = document.getElementById(form);
         var post_arg = getRequestBody(nameRequestForm);
         
					AjaxRequest.post(
					  {
					    'queryString': post_arg,
					    'url':'incs/'+script,'onSuccess':function(req)
							{ 
								alert(req.responseText); 
							}
					    ,'timeout':30000
					    ,'onTimeout':function(req){ getformpost(script,form); }
					  }
					);

 }



function validateMessage(){
                var errstring='';
                var flag=1;

	                if(document.getElementById('message').value.length<=0) { errstring=errstring+'- Message\n'; flag=0; }

                              if(flag==0) alert('Please fill out these fields correctly:\n\n'+errstring);
                               	else  {
                              		 getformpost("message.php","mesform");
					 resetForm("mesform");
					}
				return false;
}



function resetForm(formid){
document.getElementById(formid).reset();
}

	function showMenu(){
		clearInterval(timer);
		clearInterval(timer2);
		$('#submenu').slideDown();		
	}



	function hideMenu(){
		clearInterval(timer2);
		$('#submenu').slideUp();		
	}
	
	function doHideMenu(){
		timer2 =  setInterval("hideMenu()",1500);
	}


	function checkPage(){
		if(document.location.href.indexOf("#")!= -1) {
			var hash = document.location.href.substr(document.location.href.indexOf("#"));
			if(hash != '#about' && hash != '#home' && hash != '#home_2' && hash.indexOf('project')==-1  && hash != '#reach') $('#submenu').slideDown(); else $('#submenu').slideUp();
		} else $('#submenu').slideUp();
	}


	function playVideo(id){
		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			all[i].pauseMovie();
		}

		$('#holder_projvideo'+id).hide();
//		document.getElementById('projvideo'+id).playMovie();
		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			if( $(all[i]).attr("id") == 'projvideo'+id ) all[i].playMovie();
		}


	}


	function playAddVideo(id){

		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			all[i].pauseMovie();
		}


		$('#holder_addprojvideo'+id).hide();
//		document.getElementById('projvideo'+id).playMovie();

		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			if( $(all[i]).attr("id") == 'addprojvideo'+id ) all[i].playMovie();
		}
	}


	function playAddHomeVideo(id){

		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			all[i].pauseMovie();
		}


		$('#holder_addhomevideo'+id).hide();
//		document.getElementById('projvideo'+id).playMovie();

		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			if( $(all[i]).attr("id") == 'addhomevideo'+id ) all[i].playMovie();
		}
	}



	function pauseAllMovies(){
		var all = document.getElementsByTagName("embed");
		for (var i = all.length; i--;) {
			all[i].pauseMovie();
		}
	}


	function hlite(image,obj){
		obj.src="img/"+image+"_on.gif";
	}

	function dlite(image,obj){
		obj.src="img/"+image+".gif";
	}

