﻿// START Email encrytion
function email_decrypt(hashhost, hashuser) 
{
	var str = decode_base64(hashuser)+'@'+decode_base64(hashhost);
	return str;
}

function email_mailto(hashhost, hashuser)
{
	var str = email_decrypt(hashhost, hashuser);
	window.location = 'mailto:'+str;
	return str;
}

function email_write(hashhost, hashuser)
{
	var str = email_decrypt(hashhost, hashuser);
	document.write(str);
	return str;
}


var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

function encode_base64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
	  chr1 = input.charCodeAt(i++);
	  chr2 = input.charCodeAt(i++);
	  chr3 = input.charCodeAt(i++);

	  enc1 = chr1 >> 2;
	  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
	  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
	  enc4 = chr3 & 63;

	  if (isNaN(chr2)) {
		 enc3 = enc4 = 64;
	  } else if (isNaN(chr3)) {
		 enc4 = 64;
	  }

	  output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
		 keyStr.charAt(enc3) + keyStr.charAt(enc4);
   } while (i < input.length);
   
   return output;
}

function decode_base64(input) {
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
	  enc1 = keyStr.indexOf(input.charAt(i++));
	  enc2 = keyStr.indexOf(input.charAt(i++));
	  enc3 = keyStr.indexOf(input.charAt(i++));
	  enc4 = keyStr.indexOf(input.charAt(i++));

	  chr1 = (enc1 << 2) | (enc2 >> 4);
	  chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
	  chr3 = ((enc3 & 3) << 6) | enc4;

	  output = output + String.fromCharCode(chr1);

	  if (enc3 != 64) {
		 output = output + String.fromCharCode(chr2);
	  }
	  if (enc4 != 64) {
		 output = output + String.fromCharCode(chr3);
	  }
   } while (i < input.length);

   return output;
}
// END Email encrytion	


// Other vars
	// Twitter
	var iLoopControl=0;

// Functions
	// START Phone input validator
	var error = "";
	function validatePhone(fld) {
		error = "";
		var stripped = fld.replace(/[\(\)\.\-\ ]/g, '');    

		if (isNaN(parseInt(stripped))) {
			error = "digits only";
		} else if (!(stripped.length == 10)) {
			error = "enter 10 digits";
		}
		return error;
	}
	// END Phone input validator
	
	// START Input hovers
	function inputhover(idhover, special) { 
		var elemID = document.getElementById(idhover).className; 
		var last = elemID.substr(elemID.length - 5, 5); 
		var sze = document.getElementById(idhover).scrollWidth; 
		var obj, style; 
		if(document.getElementById && (obj = document.getElementById(idhover)) && (style = obj.style)) { 
			if( last != "send")
				style.backgroundPosition = '-'+sze+'px 0'; 
			else
				style.backgroundPosition = '-57px 0'; 
			if(special == 1) 
				obj.focused = true;
			if ( last == "tnorm" || last == "onial") 
				style.borderBottom = '1px #494846 solid'; 
		} 
	} 

	function inputhoverstop(idhover, special) { 
		var elemID = document.getElementById(idhover).className; 
		var last = elemID.substr(elemID.length - 5, 5); 
		var obj, style; 
		if(document.getElementById && (obj = document.getElementById(idhover)) && (style = obj.style)) { 
			if(obj.focused == true && special == 0) 
				return true;
			style.backgroundPosition = '0px 0'; 
			if(special == 1) 
				obj.focused = false;
			if ( last == "tnorm" || last == "onial" )  
				style.borderBottom = '1px #adaca5 solid'; 
		} 
	}
 	// END Input hovers
	
	// START Index Project Rotation
	var iProjectImgControl=0;
	var iProjectLinkControl=0;
	var iProjectCount;
	var iProjectLinksCount; 
	 
	function nextProjectIndex() {
		jQuery(".index-project-control span img:eq("+iProjectImgControl+")").hide();
		jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").hide();	  
		if (iProjectImgControl != iProjectCount) {
			iProjectImgControl = iProjectImgControl+1;
			iProjectLinkControl = iProjectLinkControl+1;
		}
		else {
			iProjectImgControl = 0;	  
			iProjectLinkControl = 0;	  
		}
		jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn("slow");  	  
		jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn("slow");		
	}
	// END Index Project Rotation
	
	// START Case study images rotation
	var iScreenControl = 0;
	var iScreenCount;

	function nextScreen() {
		jQuery(".screen-controler span img:eq("+iScreenControl+")").hide();  
		if (iScreenControl != iScreenCount) {
			iScreenControl = iScreenControl+1;
		}
		else {
			iScreenControl = 0;	    
		}
		jQuery(".screen-controler span img:eq("+iScreenControl+")").fadeIn("slow");  	  	
	} 
	// END Case study images rotation	

	// START Login
	var bLoginArea = true;
	var bHandleControl = 1;
	function fLoginArea(control) {
		if(bLoginArea)
		{
			if(control == 1)
			{
				jQuery("#t-already-a-client").addClass("a-already-a-client-active");
				jQuery("#login-area").show();
			}
			else			
			{
				jQuery("#t-already-a-client").removeClass("a-already-a-client-active");
				jQuery("#login-area").hide();
			}
		}
	}
	// END Login	
	
	
	// START Focus / Blur
	function changeBgPos(id,posx,posy) {
		if(!(jQuery(""+id+"").hasClass("error")))
			jQuery(""+id+"").css({"background-position":""+posx+"px "+posy+"px"});
	}
	// END Focus / Blur
	
// Onload document 
jQuery(document).ready(function(){
	// Portfolio 02/25/2011
	jQuery(".portfolio-screen-description span").fadeTo(0,0.85);
	jQuery(".portfolio-screen-link").hover(
	function() {
		jQuery(this).parent().find('.portfolio-screen-arrow').addClass('hover');
		jQuery(this).parent().find('.portfolio-screen-description-container').animate({bottom:'0px'},{queue:false,duration: 500});
		
	},
	function() {
		jQuery(this).parent().find('.portfolio-screen-arrow').removeClass('hover');
		jQuery(this).parent().find('.portfolio-screen-description-container').animate({bottom:'-169px'},{queue:false,duration: 500});
	}
	);

	
	// START Login
	jQuery("#t-already-a-client").click( function () { if(bHandleControl) { fLoginArea(1); bHandleControl = 0 } else { fLoginArea(0); bHandleControl = 1 } ; } );
		
	jQuery("#login-area input").focus( function() {	bLoginArea = false; } );
	jQuery("#login-area input").blur( function() { bLoginArea = true; } );
	
	var bBlurLogin = 1;
	jQuery('*').click(function () {
		if( jQuery(this).hasClass('login-filter') ) 
			bBlurLogin = 0;
		if( bBlurLogin )
		{
			bLoginArea = true;
			bHandleControl = 1;
			fLoginArea(0);
		}
		
		setTimeout(function(){ bBlurLogin = 1; }, 100 ); 
	}); 		

	
	jQuery("#login-area input").hover( 
		function () {
			jQuery(this).css({'color':'#fefefe'});
		},  
		function () {
			jQuery(this).css({'color':'#a4a4a4'});
		}
	);		
	
	jQuery("#login-area input").focus(
		function() {
		jQuery(this).css({'color':'#fefefe'});
		}
	);
	
	jQuery("#login-area input").blur(
		function() {
		jQuery(this).css({'color':'#a4a4a4'});
		}
	);
	// END Login
	
	// START Testimonial
	jQuery("#testi-more").click(
		function() {
			jQuery("#testi-more").hide();
			jQuery(".testimonial-more").slideDown();
		}
	);
	// END Testimonial 
	
	// START Footer rotation
	var projectFooterInterval;
	var iProjectFooter = jQuery("#already-trusted-logos > a").length;
	
	jQuery("#already-trusted-logos img, #client-list img, #awards-list img").fadeTo(0, 0.55); 
	jQuery("#already-trusted-logos img, #client-list img, #awards-list img").hover( 
		function () {
			jQuery(this).fadeTo("fast", 1);
		},  
		function () {
			jQuery(this).fadeTo(0, 0.55);
		}
	);
	// END Footer rotation
	
	// START Index projects rotation
	var projectIndexInterval;
	iProjectCount = jQuery(".index-project-control span > img").length-1;
	iProjectLinksCount = jQuery(".projects-links-control > a").length-1; 	
	
	projectIndexInterval = setInterval(nextProjectIndex,5000);
	
	jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn();
	jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn();
  
	jQuery(".index-project-control #prev").click( 
		function() {
			clearInterval(projectIndexInterval);
			projectIndexInterval = setInterval(nextProjectIndex,5000);		
			jQuery(".index-project-control span img:eq("+iProjectImgControl+")").hide();
			jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").hide();
			if (iProjectImgControl != 0) {
				iProjectImgControl = iProjectImgControl-1;
				iProjectLinkControl = iProjectLinkControl-1;
			}
			else {
				iProjectImgControl = iProjectCount;	  
				iProjectLinkControl = iProjectLinksCount; 
			}
			jQuery(".index-project-control span img:eq("+iProjectImgControl+")").fadeIn("slow");  	  
			jQuery(".projects-links-control a:eq("+iProjectLinkControl+")").fadeIn("slow");	  
		}
	);
	
	jQuery(".index-project-control #next").click( 
		function() {
			clearInterval(projectIndexInterval);
			projectIndexInterval = setInterval(nextProjectIndex,5000);
			nextProjectIndex();		  
		}
	);	
	// END Index projects rotation
	
	// START Toggle services info
	var iHeight;
	iHeight = jQuery(".extended-version").height();
	 
	jQuery(".extended-version").css({'height':iHeight});
	jQuery(".view-extended").click(
		function () { 
			jQuery(".extended-version").slideDown("slow");
			jQuery(".view-extended").hide();
			jQuery(".view-short").show();
		}
	);

	jQuery(".view-short").click(
		function () { 
			jQuery(".extended-version").slideUp("slow");
			jQuery(".view-extended").show();
			jQuery(".view-short").hide();
		}
	);
	// END Toggle services info
	
	/* SEO Landing Page */
	jQuery(".seo-landing-page .already-trusted a").fadeTo(0,0.5)
	jQuery(".seo-landing-page .already-trusted a").hover(
		function() {
			jQuery(this).stop().fadeTo('fast',1)
		},
		function() {
			jQuery(this).stop().fadeTo('fast',0.5)
		}
	);
	
	// START Twitter
	jQuery('#last_tweet').html('');
	jQuery.getJSON('http://twitter.com/status/user_timeline/oski41.json?count=10&callback=?', function(data){
		jQuery.each(data, function(index, item){
			iLoopControl = iLoopControl+1;
			if(iLoopControl<3) 
				jQuery('#last_tweet').append('<p>' + item.text.linkify() + '</p>');
		});
	
	});
	
	String.prototype.linkify = function() {
		return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) {
			return m.link(m);
		});
	};
	// END Twitter	
	
	// START Awards
	jQuery('.footer-awards div, .award-single img, .link-box').fadeTo(0,0.5);
	jQuery('.footer-awards div, .award-single img, .link-box').hover(
		function() {
			jQuery(this).stop(true,true).fadeTo('fast',1);
		},
		function() {
			jQuery(this).stop(true,true).fadeTo('fast',0.5);		
		}
	);
	// END Awards 
	
	// START About 
		jQuery(".team-box .person div").fadeTo(0,0.5);
	// END About
	
	// START Testimonial
		jQuery(".testimonial-single p span").hide();
		jQuery(".testimonial-single p a").click(
			function() {
				jQuery(this).hide();
				jQuery(this).parent("p").children("span").slideDown("fast");
			}
		);
	// END Testimonial
});
