/* Moving effects*/
$(document).ready(function(){

    $('header').fadeIn(1500);

/* for sub pages menu */
	$("#menu-subpage").hide();
	$(function () {
		$(window).scroll(function () {
			if ($(this).scrollTop() > 800) {
			  $("#menu-subpage").show();
				$('#menu-subpage').animate({opacity: 1, right: '-10px' }, {queue:false,duration:200}); 
			} else {
				$('#menu-subpage').animate({opacity: 1, right: '-490px' },{queue:false,duration:200});
			}
		});
		$('.acuteSLogo').click(function () {
			$('body,html').animate({scrollTop: 0}, 800);		
			return false;
		});
	});


/* menu */
	  $('a.mW').hover(function(){
		  $(this).animate({backgroundPosition:'-800px -412px'},{queue:false,duration:200});
	    }, function() {
      $(this).animate({backgroundPosition:'-800px -362px'},{queue:false,duration:200});
	  });

		$('a.mW').click(function(){
      $(".quote-contact-form").fadeOut('normal');
 	    $(".qc-chat").delay(1).fadeOut("normal");
      $(".qc-mob").delay(500).fadeOut("normal");
      $(".qc-email").delay(1000).fadeOut("normal");
 	  });

	  $('a.mC').click(function(){
      $(".quote-contact-form").fadeOut('normal');
 	    $(".qc-chat").delay(1).fadeOut("normal");
      $(".qc-mob").delay(500).fadeOut("normal");
      $(".qc-email").delay(1000).fadeOut("normal");
	  });

	  $('.close').hover(function(){
		  $(this).animate({backgroundPosition:'-818px -491px;'},{queue:false,duration:150});
	    }, function() {
			$(this).animate({backgroundPosition:'-818px -473px;'},{queue:false,duration:150});
	  });

	  $('.close').click(function(){
	    $(".quote-contact-form").fadeOut('normal');
	    $(".qc-chat").delay(1).fadeOut("normal");
      $(".qc-mob").delay(500).fadeOut("normal");
      $(".qc-email").delay(1000).fadeOut("normal");
	  });

    $('.insqt').click(function(){
	    $('.quote-contact-form').fadeIn('normal');
	    $(".qc-chat").delay(1).fadeOut("normal");
      $(".qc-mob").delay(500).fadeOut("normal");
      $(".qc-email").delay(1000).fadeOut("normal");
	  });

	  $('.insqt').click(function(){
	    $(".iq a").animate({backgroundPosition:'-795px -78px'},{queue:false,duration:150});
	  });

	  $('a.qc').click(function(){
      $(".qc-chat").delay(1).fadeIn("normal");
      $(".qc-mob").delay(500).fadeIn("normal");
      $(".qc-email").delay(1000).fadeIn("normal");
      $(".quote-contact-form").fadeOut('normal');
	  });

		$('a.mC').hover(function(){
			$(this).animate({backgroundPosition:'-949px -412px'},{queue:false,duration:200});
		}, function() {
				$(this).animate({backgroundPosition:'-949px -362px'},{queue:false,duration:200});
		});



		$('.iq a').hover(function(){
			$(this).animate({backgroundPosition:'-795px -78px'},{queue:false,duration:150});
		}, function() {
				$(this).animate({backgroundPosition:'-795px -21px'},{queue:false,duration:150});
		});

		$('.quickc a').hover(function(){
			$(this).animate({backgroundPosition:'-795px -293px'},{queue:false,duration:150});
		}, function() {
				$(this).animate({backgroundPosition:'-795px -250px'},{queue:false,duration:150});
		});

		$('.twt').hover(function(){
			$(this).animate({backgroundPosition:'-797px -198px;'},{queue:false,duration:150});
		}, function() {
				$(this).animate({backgroundPosition:'-797px -166px;'},{queue:false,duration:150});
		});

		$('.fb').hover(function(){
			$(this).animate({backgroundPosition:'-839px -198px;'},{queue:false,duration:150});
		}, function() {
				$(this).animate({backgroundPosition:'-839px -166px;'},{queue:false,duration:150});
		});

		$('.ln').hover(function(){
			$(this).animate({backgroundPosition:'-881px -198px;'},{queue:false,duration:150});
		}, function() {
				$(this).animate({backgroundPosition:'-881px -166px;'},{queue:false,duration:150});
		});

		$('.email').hover(function(){
			$(".email span").animate({backgroundPosition:'-19px -69px;'},{queue:false,duration:150});
		}, function() {
				$(".email span").animate({backgroundPosition:'-19px -6px;'},{queue:false,duration:150});
		});

		$('li.skype').hover(function(){
			$(".skype span").animate({backgroundPosition:'-19px -196px;'},{queue:false,duration:150});
		}, function() {
				$(".skype span").animate({backgroundPosition:'-19px -133px;'},{queue:false,duration:150});
		});

		$('li.phone').hover(function(){
			$(".phone span").animate({backgroundPosition:'-19px -323px;'},{queue:false,duration:150});
		}, function() {
				$(".phone span").animate({backgroundPosition:'-19px -260px;'},{queue:false,duration:150});
		});

		$('.quote-contact-form').mouseover(function(){
	  	$(".iq a").animate({backgroundPosition:'-795px -78px'},{queue:false,duration:150});
		});

		$('.quote-contact-form').mouseleave(function(){
	  	$(".iq a").animate({backgroundPosition:'-795px -21px'},{queue:false,duration:150});
		});


	/* Project SLID SHOW */
		$(function(){
			$('#project-php').slides({
				generateNextPrev: true,
			});
			$('#project-symfony').slides({
				generateNextPrev: true,
			});
			$('#project-drupal').slides({
				generateNextPrev: true,
			});
			$('#project-wordpress').slides({
				generateNextPrev: true,
			});
			$('#project-joomla').slides({
				generateNextPrev: true,
			});
			$('#project-magento').slides({
				generateNextPrev: true,
			});
			$('#project-fbtwt').slides({
				generateNextPrev: true,
			});
			$('#project-iphone').slides({
				generateNextPrev: true,
			});
			$('#project-android').slides({
				generateNextPrev: true,
			});
			$('#project-logo').slides({
				generateNextPrev: true,
			});
			$('#project-html5').slides({
				generateNextPrev: true,
			});
			$('#project-website').slides({
				generateNextPrev: true,
			});
		});




	/* Set up variables  */
    var $el, $currentTitle, $otherTitle,
		$allTitles = $("dt").css({padding: 0,"cursor": "pointer"}),
    $allCells = $("dd").css({position: "relative",top: 0,left:0, display: "none"});
   	$("#porjects").delegate("h4","click", function(e) {
        if ( !$(this).parent().hasClass("curCol") ) {
       	e.preventDefault();
        $(this).next().find('dt:first').click();
    		
    		
    		$(".curCol h4.php").animate({backgroundPosition:'-6px -770px',opacity: 0.9, left: '+165'},{queue:false,duration:500});
   		
				$(".curCol h4.symfony").animate({backgroundPosition:'-92px -601px'},{queue:false,duration:500});
				$(".curCol h4.drupal").animate({backgroundPosition:'-181px -728px'},{queue:false,duration:500});
				$(".curCol h4.wordpress").animate({backgroundPosition:'-269px -653px'},{queue:false,duration:500});	
				$(".curCol h4.joomla").animate({backgroundPosition:'-359px -659px'},{queue:false,duration:500});		
				$(".curCol h4.magento").animate({backgroundPosition:'-448px -664px'},{queue:false,duration:500});
				$(".curCol h4.fbtwt").animate({backgroundPosition:'-538px -509px'},{queue:false,duration:500});	
				$(".curCol h4.iphone").animate({backgroundPosition:'-627px -638px'},{queue:false,duration:500});	
				$(".curCol h4.android").animate({backgroundPosition:'-714px -709px'},{queue:false,duration:500});	
				$(".curCol h4.logo").animate({backgroundPosition:'-806px -746px'},{queue:false,duration:500});
				$(".curCol h4.html5").animate({backgroundPosition:'-893px -514px'},{queue:false,duration:500});	
				$(".curCol h4.website").animate({backgroundPosition:'-983px -544px'},{queue:false,duration:500});		
		    }
    });
    $("#porjects").delegate("dt", "click", function() {
      $el = $(this);
        
      	$(".curCol h4.php").animate({backgroundPosition:'-6px -880px',opacity: 1, left: '0'},{queue:false,duration:500});
      	
      	$(".curCol h4.symfony").animate({backgroundPosition:'-92px -880px'},{queue:false,duration:500});	
      	$(".curCol h4.drupal").animate({backgroundPosition:'-179px -880px'},{queue:false,duration:500});
      	$(".curCol h4.wordpress").animate({backgroundPosition:'-269px -880px'},{queue:false,duration:500});
      	$(".curCol h4.joomla").animate({backgroundPosition:'-359px -880px'},{queue:false,duration:500});		
    		$(".curCol h4.magento").animate({backgroundPosition:'-448px -880px'},{queue:false,duration:500});	
    		$(".curCol h4.fbtwt").animate({backgroundPosition:'-538px -880px'},{queue:false,duration:500});	
				$(".curCol h4.iphone").animate({backgroundPosition:'-627px -880px'},{queue:false,duration:500});	
				$(".curCol h4.android").animate({backgroundPosition:'-713px -880px'},{queue:false,duration:500});	
				$(".curCol h4.logo").animate({backgroundPosition:'-807px -880px'},{queue:false,duration:500});
				$(".curCol h4.html5").animate({backgroundPosition:'-893px -880px'},{queue:false,duration:500});	
				$(".curCol h4.website").animate({backgroundPosition:'-983px -880px'},{queue:false,duration:500});	
    
      if (!$el.hasClass("current")) {
      	$currentTitle = $el.parent().parent();
				$otherTitles = $(".tech-col").not($currentTitle);
        $allTitles = $("dt").not(this);
        $allCells.slideUp();
        $el.animate({opacity:100}).next().slideDown();
        $currentTitle.animate({width: 250}).addClass("curCol");
        $otherTitles.animate({width: 87}).removeClass("curCol");
        $allTitles.removeClass("current");
        $el.addClass("current");
        }
    });
	$("#starter").trigger("click");

//Background Moving  (Parallax)
	var $window = $(window);
	var $homeBG = $('#home');
	var $aboutBG = $('#our-work');
	var $contactBG = $('#contact');
	var chameleon = $("#home .chameleon");
	var bubbles = $("#home .bubbles");
	var bodyBg = $("body");
	var portfolioArrowBg = $("#our-work .portfolioArrowBg");
	var contactMapBg = $("#contact .contactMapBg");
	var map = $('.contactAdsBubble');
	var windowHeight = $window.height(); //get the height of the window

	$('#home, #work, #our-work, .contactAdsBubble, #contact').bind('InnerBgs', function (event, visible) {
			if (visible == true) {
                $(this).addClass("InnerBgs");
			} else {
                $(this).removeClass("InnerBgs");
			}
		});

	//function that places the navigation in the center of the window
		function RepositionNav(){
		var windowHeight = $window.height(); //get the height of the window
		var navHeight = $('.akarmi').height() / 2;
		var windowCenter = (windowHeight / 2);
		var newtop = windowCenter - navHeight;
		$('.akarmi').css({"top": newtop}); //set the new top position of the navigation list
	}

/** scrolls of background's position* */

	function newPos(x, windowHeight, pos, adjuster, inertia){
		return x + "% " + (-((windowHeight + pos) - adjuster) * inertia)  + "px";
	}
	function newPosBottom(x, maxPos, pos, maxTop, inertia){
		return x + "% " + (((maxPos - pos) * inertia)+maxTop)  + "px";
	}

// Scrolls of background Move
	function Move(){
		var pos = $window.scrollTop(); //position of the scrollbar
		windowHeight = $window.height();
		var bodyHeight = $('body').height();
		if($homeBG.hasClass("InnerBgs")){
      $homeBG.animate({'backgroundPosition': newPos(50, 0, pos, 0, 0.2)},{queue:false,duration:500});
      chameleon.animate({'backgroundPosition': newPos(50, 0, pos, 0, 0.3)},{queue:false,duration:300});
      bubbles.animate({'backgroundPosition': newPos(50, 0, pos, 0, 1.5)},{queue:false,duration:700});
   	 }
		if($aboutBG.hasClass("InnerBgs")){
      portfolioArrowBg.animate({'backgroundPosition': newPos(0, 0, pos, 1100, -0.5)},{queue:false,duration:400});
		}
		if($contactBG.hasClass("InnerBgs")){
			var maxMapBottom = bodyHeight-windowHeight;
			var maxMapBottomTop = windowHeight - 700;
			map.animate({'backgroundPosition': newPosBottom(50, maxMapBottom, pos, maxMapBottomTop, 0.2)},{queue:false,duration:200});
      contactMapBg.animate({'backgroundPosition': newPos(50, 0, pos, 2400, -0.4)},{queue:false,duration:500});
		}
  }
		RepositionNav();
		$window.resize(function(){
		Move();
		RepositionNav();
	});
	$window.bind('scroll', function(){
		Move();
	});
});


/* Background position anim */
(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			start = toArray(start);
			fx.start = [start[0],start[2]];
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	};
})(jQuery);


/* Whole Page Scroll  */
$(function(){
    $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
        && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                return false;
            }
        }
    });
});


/* Instant Quote Jquery */

var errinstant = false;
var errcontact = false;

function clearText(id,value,value2,class_name){
	if($("#"+id).val() == value || $("#"+id).val() == value2){
			$("#"+id).val("");
			$("#"+id).attr('class',class_name);
	}
}

function FillText(id,value,class_name){
	if($("#"+id).val() == ""){
		$("#"+id).val(value);
		$("#"+id).attr('class',class_name);
	}
}

function chkFrmInstant(frmInstant){
    var formclear = true;
    var firstname = trim(document.getElementById("Quotation_fullname").value);
    if(firstname=="" || firstname=="Fullname" || firstname=="Please enter Fullname"){
        document.getElementById("Quotation_fullname").className = "input_error textbox namebox";
        document.getElementById("Quotation_fullname").value = "Please enter Fullname";
       $('#Quotation_fullname').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
        errinstant=true;
        formclear = false;
    }else {
		    $('#Quotation_fullname').animate({backgroundPosition:'-39px -1676px'},{queue:false,duration:200});
	  }
    var telephone = trim(document.getElementById("Quotation_phone").value);
    if(telephone=="" || telephone=="Phone" || telephone=="Please enter valid Phone No"){
        document.getElementById("Quotation_phone").className = "input_error textbox phonebox";
        document.getElementById("Quotation_phone").value = "Please enter valid Phone No";
        $('#Quotation_phone').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
        formclear = false;
    }
    else if(telephone.length<6){
        document.getElementById("Quotation_phone").className = "input_error textbox phonebox";
        document.getElementById("Quotation_phone").value = "Please enter valid Phone No";
        $('#Quotation_phone').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
        formclear = false;
    }else {
        $('#Quotation_phone').animate({backgroundPosition:'-39px -1676px'},{queue:false,duration:200});
	  }
    var intrested = trim(document.getElementById("Quotation_intreased").value);
    if(intrested=="" || intrested=="Intreased in..." || intrested=="Please enter your are Intreased..."){
        document.getElementById("Quotation_intreased").className = "input_error textbox";
        document.getElementById("Quotation_intreased").value = "Please enter your are Intreased...";
        $('#Quotation_intreased').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
        formclear = false;
    }else {
		      $('#Quotation_intreased').animate({backgroundPosition:'-39px -1676px'},{queue:false,duration:200});
	  }
    var email_address = trim(document.getElementById("Quotation_email").value);
    if(email_address=="" || email_address=="email" || email_address=="Please enter valid email"){
        document.getElementById("Quotation_email").className = "input_error textbox";
        document.getElementById("Quotation_email").value = "Please enter valid email";
        $('#Quotation_email').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
        formclear = false;
    }
      else if(validateEmail(email_address)==null){
        document.getElementById("Quotation_email").className = "input_error textbox";
        document.getElementById("Quotation_email").value = "Please enter valid email";
		   	$('#Quotation_email').animate({backgroundPosition:'-39px -1723px'},{queue:false,duration:200});
    		formclear = false;
    }else {
		    $('#Quotation_email').animate({backgroundPosition:'-39px -1676px'},{queue:false,duration:200});
	  }
    var message = trim(document.getElementById("Quotation_message").value);
    if(message=="" || message=="Message" || message=="Please enter Message"){
	      document.getElementById("Quotation_message").className = "input_error";
        document.getElementById("Quotation_message").value = "Please enter Message";
        $('#Quotation_message').animate({backgroundPosition:'-387px -1793px'},{queue:false,duration:200});
        formclear = false;
    }
    else {
		    $('#Quotation_message').animate({backgroundPosition:'-387px -1676px'},{queue:false,duration:200});
	  }
    if(formclear==false){
        return false;
    }
    else{
        var xmlhttp;
        if (window.XMLHttpRequest){
     			xmlhttp=new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
        }
        else {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); // code for IE6, IE5
        }
        $(".process").delay(10).fadeTo("slow",0.7);
        $("#Quotation").delay(10).fadeTo("slow",0.5);
        var sendUrl = "sendinfo.php?Quotation_fullname="+firstname+"&Quotation_intreased="+intrested+"&Quotation_phone="+encodeURIComponent(telephone)+"&Quotation_email="+email_address+"&Quotation_message="+message;
        xmlhttp.open("GET",sendUrl);
        xmlhttp.send(null);
        xmlhttp.onreadystatechange=function(){
              if (xmlhttp.readyState==4 && xmlhttp.status==200){
                  if(xmlhttp.responseText=="success"){
                     $(function() {
                           //$('.quote-contact-form').fadeOut('normal');
                           $('#msgquot').delay(100).fadeIn('normal', function() {
                             $(this).delay(1000).fadeOut();
                             $(".process").delay(10).fadeOut("normal");
                             $("#Quotation").delay(300).fadeTo("slow",1);
                             
                           });
                     });
                     document.getElementById("Quotation_fullname").value = "Fullname"
                     document.getElementById("Quotation_intreased").value = "Intreased in..."
                     document.getElementById("Quotation_phone").value = "Phone"
                     document.getElementById("Quotation_email").value = "email"
                     document.getElementById("Quotation_message").value = "Message"
                     $("#Quotation_fullname").attr('class',"textbox namebox");
                     $("#Quotation_intreased").attr('class',"textbox");
                     $("#Quotation_phone").attr('class',"textbox phonebox");
                     $("#Quotation_email").attr('class',"textbox");
                     $("#Quotation_message").attr('class',"");
                  }
              }
        }
        return false;
    }
    return false;
}

function validateEmail(email){
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return email.match(re)
}
function trim(str){
    if(!str || typeof str != 'string')
        return null;
    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}


