if($.browser.msie && $.browser.version=="6.0") 
{ 
 msg = "Your Internet Explorer is very old! \nYou may be able to view site but not experience full functionality. \n\nTo get the best possible experience using our website we recommend that you upgrade to a newer version or use better browsers."
 alert(msg);
}

var addthis_share =
{
    url: "http://www.coherendz.com",
    title: "Coherendz - Websites, Web Apps and Business Solutions.",
    description: "Coherendz is a Business Development Firm in Hyderabad, India, providing web based technology solutions.",
	email_template: "Coherendz",
    templates: {
                   twitter: 'Hey, this website is interesting! Check out {{url}} via @coherendz'
               }
	
};

$.clientCoords = function() {
	var dimensions = {width: 0, height: 0};
	if (document.documentElement) {
		dimensions.width = document.documentElement.offsetWidth;
		dimensions.height = document.documentElement.offsetHeight;
	} 
	else{
		if (window.innerWidth && window.innerHeight) {
			dimensions.width = window.innerWidth;
			dimensions.height = window.innerHeight;
		}
	}
	return dimensions;
}

function validate(formData, jqForm, options) { 
	   for (var i=0; i < formData.length; i++) { 
			if (!formData[i].value) { 
//				alert('Please enter a value for both Username and Password'); 
			   $('#responseMsg').html("<span class='error'>Please fill all the fields!</span>");
//			   $('#contact-form').find(formData[i].name).hide();
			return false
			}
			else
				$('#responseMsg').html('<img src="media/ajax-loader.gif" height="20px;"/>');
		}
		
} 

// post-submit callback 
function formResponse(responseText, statusText, xhr, $form)  { 
	$('#responseMsg').html(responseText); 
}

$(document).ready(function(){
	var ww = $.clientCoords().width;
	var wh = $.clientCoords().height;
	var cx 	= ww/2;					var cy	= wh/2-70;		//center
	var offx1= 200;					var offy1= -90;			//distance from center
	var offx2=520;					var offy2= -60;			//distance from center
	var offx12= 50;	
	var	fh = 150;
	var r=50;

	var n0w = $(".level0").outerWidth();	var n0h = $(".level0").outerHeight();
	var n1w = $(".level1").outerWidth();	var n1h = $(".level1").outerHeight();	
	var n2w = $(".level2").outerWidth();	var n2h = $(".level2").outerHeight();	
	
//	var b1w = 300;	var b1h=200; 
	var n00x= cx-n0w/2;						var n00y = cy-n0h/2;
//	alert(n0w+" "+n0h+" "+n1w+" "+n1h+" ");
	var n11x= cx-n1w/2+offx1;				var n11y = cy-n1h/2-offy1;
	var n12x= cx-n1w/2-offx1;				var n12y = cy-n1h/2-offy1;
	
	var n21x= cx-n2w/2+offx2;				var n21y = cy-n2h/2-offy2;
	var n22x= cx-n2w/2-offx2;				var n22y = cy-n2h/2-offy2;

//	alert(b1h+" "+b1w);
	$("#canvas").css("height",wh-fh).css("width",ww);
	$("#footer").css("height",fh).css("width",ww);
	$("#content-box").css("width",ww).css("height",0);
	$("#node00").css("left",n00x).css("top",n00y);
	$("#node11").css("left",n11x).css("top",n11y);
	$("#node12").css("left",n12x).css("top",n12y);
	$("#node21").css("left",n21x).css("top",n21y);
	$("#node22").css("left",n22x).css("top",n22y);	
	
	$(".level1").animate({opacity:.8},500);
	$(".level2").animate({opacity:.05},500);	
//	$("#node12").animate({opacity:.1},500);
//	$("#node21").animate({opacity:1},500);
	
	$("#canvas").hover(function(){
		if($("#pan").hasClass("open")){
			$(".level2").animate({opacity:1},500)
		}
		else{
			$(".level1").animate({opacity:1},500)
			$(".level2").animate({opacity:.2},500)		
		};
	});

	$("#footer").hover(function(){
		if($("#pan").hasClass("open")){
			$(".level2").animate({opacity:.1},500)
		}
		else{
			$(".level1").animate({opacity:.1},500),
			$(".level2").animate({opacity:.1},500)
		};
	});

	
	$("#node00").click(function(){
			$("#pan").animate({left:0,top:0},1000).removeClass("open")
	});	

	$("#node11").click(function(){
		mx= -offx2+offx1;
		my= offy1;// -n11y-offy1;
		$("#pan").animate({left:mx},800),		
		$("#pan").animate({top:my},800).addClass("open"),
		$("#node11").animate({opacity:1},1000),
		$("#node21").animate({opacity:1},1000)
		
	});	

	$("#node12").click(function(){
		mx= offx2-offx1;
		my= offy1;// -n11y-offy1;
		$("#pan").animate({left:mx},800),		
		$("#pan").animate({top:my},800).addClass("open"),
		$("#node12").animate({opacity:1},1000),
		$("#node22").animate({opacity:1},1000)

	});	
	
	var hash = window.location.hash.substr(1);
	var href = $('a.nav').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-3)){
			var toLoad = hash+'.php #content';
// 			$("#content-box").animate({height:wh-fh-5},1000).addClass("open"),
			$('#content').load(toLoad)
		}											
	});

	$('a.nav').click(function(){
		var toLoad = $(this).attr('href')+' #content';

		if($("#content-box").hasClass("open")){
			
		}
		else
		{
			$("#content-box").animate({height:wh-fh-5},1000).addClass("open");
		}

		$('#content').hide('fast',loadContent);
		$('#load').remove();		
		$('#load-box').append('<span id="load"><img src="media/ajax-loader.gif" /></span>');
		$('#load').fadeIn('normal');		
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-3);	
		var page =  window.location.hash;
		
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent);
		}
		function showNewContent() {
			if(page == '#contact'){
			 
			 	var options = { 
					target:        '#responseMsg',   // target element(s) to be updated with server response 
					beforeSubmit:  validate,  // pre-submit callback 
					success:       formResponse,
					resetForm: 		true,
					url:		   'sendmail.php'
			    }; 

				$('#content').find('label').inFieldLabels().end()
				.find('#contact-form').ajaxForm(options) 
				.end().show('normal',hideLoader());  

			}
			else if(page == '#portfolio'){
				$('#content').find('.gallery a').lightBox({txtImage: 'Design'}).end().show('normal',hideLoader());
			}
			else if(page == '#team'){
				$('#content').find('a.nav').click({txtImage: 'Design'}).end().show('normal',hideLoader());
			}
			else{
				$('#content').show('normal',hideLoader());
			}

		}
		function hideLoader() {
			$('#load').fadeOut('normal');
		}
		return false;
	});
	
	$(".close-box").click(function(){
		$("#content-box").animate({height:0},1000).removeClass("open");
		$("#talk-box-wrapper").hide(1000).removeClass("open")
	});
	
});
