jQuery(document).ready(function () {
		
    $('#panel').jScrollPane({
        dragMaxHeight: 22,
        scrollbarWidth: 21
    });
		
						 
	var email = new LiveValidation('email');
	email.add( Validate.Email );
	email.add( Validate.Presence );
	
	var name = new LiveValidation('name');
	name.add(Validate.Presence);
	
	var contact = new LiveValidation('phone');
	contact.add( Validate.Numericality);
	contact.add(Validate.Presence);
	
	var query = new LiveValidation('query');
	query.add(Validate.Presence);
	
	
	var actionButton;
    mainMenuResize(); //Header and footer Resize
    backgroundImg();  //Panning Background Image
	// bodyHeight(); 	  //Calculate Background Height
	//loadingImg();	  //Loading External Images on Carousel Click
	var actionButton=0;
	var animateState =0;
	var heightofwindow;
	var initHeight;
	
    $('#slideShow').slideUp();
	
  
    var startPos = $(".mainContent").offset().top;  
	//$('#outer_container').height($('.homeContainer').height());
	$('#outer_container').height(1300);
	
	//alert(initHeight);
	if ( $.browser.msie ) {
 		// alert( $.browser.version );
		heightofwindow = document.documentElement.clientHeight - 250 - 125 -80;
	}
	else{
	    heightofwindow = window.innerHeight - 250 - 125 -80;
	}
	actionButton = heightofwindow+60;
	$(".drop").css("top","250px")
    $(".drop").click(function () {  
		var newPath="images/campusBack.png";
		$(".drop img").attr("src",newPath);
		
	   $(".mainHomeContentBar .contentArea .collapseArea").slideToggle("slow");
	 	
		if (animateState ==0){
			animateState=1;
			actionButton = Math.abs(actionButton);
			$(".drop").animate({"top": "+=" + actionButton + "px"}, "slow");      
			$(".promotionArea").fadeOut("slow");
			$(".mainContent").animate({"top": "+=" + heightofwindow + "px"}, "slow", function () {
				$('#slideShow').slideDown("slow");           
				panView();
			});			
			$('body').css("overflow","hidden");
		}
		
		else if (animateState ==1){
			animateState=0;
			var newPath="images/campus.png";
			$(".drop img").attr("src",newPath);
			heightofwindowminus = heightofwindow * (-1);
			if(actionButton > 0){
				actionButton = actionButton * (-1);
			}
			
			$imagePan.unbind("mousemove");
			$(".drop").animate({"top": "+=" + actionButton + "px"}, "slow");    
			$(".mainContent").animate({
				"top": "+=" + heightofwindowminus + "px"
			}, "slow", function () {
				
				
				 $('#outer_container').height(initHeight);	
				 $('.panning').css("margin-top","10px");
				 $('#imagePan .container').css("top","-10px");
				$('#slideShow').slideUp("slow",function(){
					 $(".promotionArea").fadeIn("slow");
				});      
				
			});
			$('body').css("overflow-y","visible");			
		}
    });
});

function backgroundImg() {
    $("#mycarousel li a").click(function () {
		var imgPath = $(this).attr('rel');
		$("#imagePan .container div img").attr("src",imgPath);
		$(".preLoader").show();
		$('#imagePan .container div img').load(function() {
			$(".preLoader").hide();													
		})
    });

}

function mainMenuResize() {
    //this is the width of the window
    var widthofwindow = $(window).width();
    //remember middle width always remains 970px
    var middleWidth = 966;
    //calculate outisde width
    //consider left width and right width to be same
    var outsideWidth = (widthofwindow - middleWidth) / 2;
	
    //set the width on the page
    $('.wrapperLeft').css('width', outsideWidth + 'px');
    $('.wrapperRight').css('width', outsideWidth + 'px');
    $('.wrapper').css('width', middleWidth + 'px');

    $('.footerLeft').css('width', outsideWidth + 'px');
    $('.footerRight').css('width', outsideWidth + 'px');
    $('.footer').css('width', middleWidth + 'px');
}

function submitForm(){
	//get the values for the form 			
	var queryAdd = $("#query").val();
	var nameAdd = $("#name").val();
	var phoneAdd = $("#phone").val();
	var emailAdd = $("#email").val();
	
	//set post data
	var post_data = "action=queryFromAdd&email="+emailAdd+"&name="+nameAdd+"&phone="+phoneAdd+"&query="+queryAdd;

	//send the ajax to the following place	
	$.ajax({
		   type: "POST",
		   url: "api/ajax_action.php",
		   data: post_data,
		   success: function(result){
				alert(result);
		   }
	 });
	
}

function panView() {
	
    $outer_container = $("#outer_container");
    $imagePan_panning = $("#imagePan .panning");
    $imagePan = $(".homeContainer ,#outer_container");
    $imagePan_container = $("#imagePan .container");
	
    $outer_container.css("top", (0) / 2);
	$outer_container.css("left", (0) / 2);
	$imagePan_panning.css("margin-top", ($imagePan.height() - $imagePan_panning.height()) / 2 + "px");
    containerWidth = $imagePan.width();
    containerHeight = $imagePan.height();
    totalContentW = $imagePan_panning.width();
    totalContentH = $imagePan_panning.height();
    $imagePan_container.css("width", totalContentW).css("height", totalContentH);
	
	//alert($imagePan_container.css("left"));

    function MouseMove(e) {
        var mouseCoordsX = ((e.pageX - $imagePan.offset().left));
        var mouseCoordsY = ((e.pageY - $imagePan.offset().top)*3);
        var mousePercentX = mouseCoordsX / containerWidth;
        var mousePercentY = mouseCoordsY / containerHeight;
        var destX = -(((totalContentW - (containerWidth)) - containerWidth) * (mousePercentX));
        var destY = -(((totalContentH - (containerHeight)) - containerHeight) * (mousePercentY));
        var thePosA = mouseCoordsX - destX;
        var thePosB = destX - mouseCoordsX;
        var thePosC = mouseCoordsY - destY;
        var thePosD = destY - mouseCoordsY;
        var marginL = $imagePan_panning.css("marginLeft").replace("px", "");
        var marginT = $imagePan_panning.css("marginTop").replace("px", "");
        var animSpeed = 500; //ease amount
        var easeType = "easeOutCirc";
        if (mouseCoordsX > destX || mouseCoordsY > destY) {
            //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
            $imagePan_container.stop().animate({
                left: -thePosA - marginL,
                top: -thePosC - marginT
            }, animSpeed, easeType); //with easing
        } else if (mouseCoordsX < destX || mouseCoordsY < destY) {
            //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
            $imagePan_container.stop().animate({
                left: thePosB - marginL,
                top: thePosD - marginT
            }, animSpeed, easeType); //with easing
        } else {
            $imagePan_container.stop();
        }
    }
    //$imagePan_panning.css("margin-left", ($imagePan.width() - $imagePan_panning.width()) / 2).css("margin-top", ($imagePan.height() - $imagePan_panning.height()) / 2);

	//$('#imagePan .container div img').css("margin-top", "-"+(($imagePan.height() - $imagePan_panning.height()) / 2)+"px");
    $imagePan.bind("mousemove", function (event) {
		MouseMove(event);
    });

}

$(window).resize(function () {
	mainMenuResize();
	backgroundImg(); 
});
