
$(document).ready(function(){
    var speed = 0.5;
    var blue_bar_width = -1 * $("#blueBarContainer").width();
    var base_blue_slider_frame_left = parseInt($("#blueSliderFrame").css('left'));
    var orange_bar_width = -1 * $("#orangeBarContainer").width();
    var top_bar_width = -1 * $("#top .center").width();
    var orange_big_bar_width = orange_bar_width;
    var currentView="home";

    function showBlueContainer(show, callback){
        if(show){
            $("#blueBarContainer").css('display','block').animate({'left':0},speed*1100,callback);
            $("#blueSliderFrame").animate({'left':base_blue_slider_frame_left},1000);
        }else{
            $("#blueBarContainer").animate({'left':blue_bar_width+$(document).width()-930},speed*1100,callback);  
            $("#blueSliderFrame").animate({'left':blue_bar_width},1000);
        }
    }
    
    function showOrangeContainer(show, callback){
        if(show){
            $("#orangeBarContainer").css('display','block').animate({'right':0},speed*750, callback);
 
        }else{
            
            $("#orangeBarContainer").animate({'right':orange_bar_width},speed*750,callback);
     
        }
    }
   
    function showBigBarContainer(show, page, callback){
        if(show){
           if (page=="ITS"){
               document.getElementById('BP_header').innerHTML="Custom IT solutions.";
               $("#orangeBigBarContainer").css('display','block').animate({'right':0},speed*750, callback);                        
			$('#BP_desc').html('<img src="img/loading.gif" class="loadingImg"/>');
			$('#BP_desc').load("BP_ITS_desc.xml");
			$('#BP_area1').html('<img src="img/loading.gif"  class="loadingImg"/>');
			$('#BP_area1').load("BP_ITS1.xml");
			$('#BP_area2').html('<img src="img/loading.gif"  class="loadingImg"/>');
		     $('#BP_area2').load('BP_ITS2.xml');
			$('#BP_area3').html('<img src="img/loading.gif"  class="loadingImg"/>');
			$('#BP_area3').load("BP_ITS3.xml");
           }
           if (page=="MOB"){
               document.getElementById('BP_header').innerHTML="We do mobile.";
               $("#orangeBigBarContainer").css('display','block').animate({'right':0},speed*750, callback);
            	$('#BP_desc').html('<img src="img/loading.gif" class="loadingImg"/>');
			$('#BP_desc').load("BP_MOB_desc.xml");
			$('#BP_area1').html('<img src="img/loading.gif"  class="loadingImg"/>');
			$('#BP_area1').load("BP_MOB1.xml");
			$('#BP_area2').html('<img src="img/loading.gif"  class="loadingImg"/>');
		     $('#BP_area2').load('BP_MOB2.xml');
			$('#BP_area3').html('<img src="img/loading.gif"  class="loadingImg"/>');
		     $('#BP_area3').load('BP_MOB3.xml');
           }
           
          if (page=="WEB"){
               document.getElementById('BP_header').innerHTML="We do web.";
               $("#orangeBigBarContainer").css('display','block').animate({'right':0},speed*750, callback);
               $('#BP_desc').html('<img src="img/loading.gif" class="loadingImg"/>');
			$('#BP_desc').load("BP_WEB_desc.xml");
			$('#BP_area1').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>');
			$('#BP_area1').load("BP_WEB1.xml");
			$('#BP_area2').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>');
			$('#BP_area2').load("BP_WEB2.xml");
			$('#BP_area3').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>');
			$('#BP_area3').load("BP_WEB3.xml");
           }
           
          if (page=="APP"){
               document.getElementById('BP_header').innerHTML="Our Approach.";
            $("#orangeBigBarContainer").css('display','block').animate({'right':0},speed*750, callback);
			$('#BP_area1').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>');
			$('#BP_area1').load("BP_area3.xml");
           }
          if (page=="ABT"){
               document.getElementById('BP_header').innerHTML="About Us.";
            $("#orangeBigBarContainer").css('display','block').animate({'right':0},speed*750, callback);
			$('#BP_area1').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>');
			$('#BP_area1').load("BP_area3.xml");
           }
           
        }else{
            $("#orangeBigBarContainer").animate({'right':orange_big_bar_width},speed*750,callback);    
        }
    }
    
    
    
    
	/*
	function hideBigBarContainer(hide, callback){
        if(hide){
            $("#orangeBigBarContainer").css('display','block').animate({'right':orange_big_bar_width},speed*750, callback);
			$('#BP_area1').html(' ');
			//$('#BP_area1').load("BP_area1.html");
			$('#BP_area2').html(' ');
			//$('#BP_area2').load("BP_area2.html");

        }else{
            $("#orangeBigBarContainer").animate({'right':0},speed*750,callback);    
        }
    } */
	
	function showBParea(destination, url){
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.open("GET",url,false);
		//xmlhttp.send(null); 
		
		if (xmlhttp.readyState==4)
		{	
			if(xmlhttp.status==200) {
			
				document.getElementById(destination).innerHTML='test';//xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
	
	
	function loadXMLDoc(url)
		{
		xmlhttp=null;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE5, IE6
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=onResponse;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	
	function onResponse()
	{ //alert(xmlhttp.readyState+" "+xmlhttp.status+" "+xmlhttp.responseText);
	if(xmlhttp.readyState!=4) return;
	/*if(xmlhttp.status!=200)
	  {
	  alert("Problem retrieving XML data");
	  return;
	  } */
	  document.getElementById("BP_area1").innerHTML=xmlhttp.responseText;
	}
     
     function minimizeBigPane()
     {       
            document.getElementById("BigPane").style.height="270px";
            document.getElementById("orangeBigBarEnd").style.height="330px";
            document.getElementById("orangeBigBarContent").style.height="330px";
            document.getElementById("orangeBigBarContainerBg").style.height="330px";   
     }
     
     function restoreBigPane()
     {
            document.getElementById("BigPane").style.height="700px";
            document.getElementById("orangeBigBarEnd").style.height="711px";
            document.getElementById("orangeBigBarContent").style.height="712px";
            document.getElementById("orangeBigBarContainerBg").style.height="713px";
     }
     
     
     
     
     
     
	
    //$("#blueBarContainer").css('left',blue_bar_width);
    $("#orangeBarContainer").css('right',orange_bar_width);
    $("#orangeBigBarContainer").css('right',orange_big_bar_width);
    //$("#top .center").css({'position':'relative','top':-100,'display':'block'});
    $("#orangeSliderContent .medium_thumbs_list li").css('padding-left','100%');
      //  return;

    showBlueContainer(true, function(){
        
        showOrangeContainer(true, function(){
            var items = $("#orangeSliderContent .medium_thumbs_list li");            
            for(var i = 0; i < items.length; i++){
                $(items[i]).delay(i*200).animate({'padding-left':0},speed*1000);
            }
            
          //  $("#top .center").animate({'top':0},speed*5000)
        });
    });
    
    //Solutions
    //$('#liArea1').click(function(){
    //    document.getElementById('btnBack').style.display="block";
//		restoreBigPane();
	//	showBlueContainer(false, function(){
		
      //      showOrangeContainer(false, function(){
		//		window.location="its.html";
             //   showBigBarContainer(true,"ITS");
               // currentView="BigPane";
         //    });
       // });
    //});
 
	
     //ReadMore
        $('#btnRM').click(function(){
        document.getElementById('btnBack').style.display="block";
 restoreBigPane();
		showBlueContainer(false, function(){
            showOrangeContainer(false, function(){
                showBigBarContainer(true,"ITS");
                currentView="BigPane";
            });
        });
    });
    
    
     
   //  $('#liArea2').click(function(){
    //    document.getElementById('btnBack').style.display="block";
    //      document.getElementById('BP_header').innerHTML="We do mobile.";
	//	showBlueContainer(false, function(){
    //        showOrangeContainer(false, function(){
    //            showBigBarContainer(true,"MOB");
     //                           currentView="BigPane";
//            });
 //       });
 //   });
  //       $('#liArea3').click(function(){
  //      document.getElementById('btnBack').style.display="block";
        // document.getElementById('BP_header').innerHTML="We do web.";
		// showBlueContainer(false, function(){
            // showOrangeContainer(false, function(){
                // showBigBarContainer(true,"WEB");
                
                                // currentView="BigPane";

            // });
        // });
    // });
         
          //Approach
               $('#btnApp').click(function(){
               document.getElementById('btnBack').style.display="block";
               document.getElementById('BP_header').innerHTML="We do mobile.";
               showBlueContainer(false, function(){
                 showOrangeContainer(false, function(){
                   showBigBarContainer(true,"APP");
                     currentView="BigPane";
                 });
             });
         });   
          //AboutUs
               $('#btnAbout').click(function(){
               document.getElementById('btnBack').style.display="block";
               document.getElementById('BP_header').innerHTML="We do mobile.";
               showBlueContainer(false, function(){
                 showOrangeContainer(false, function(){
                   showBigBarContainer(true,"ABT");
                     currentView="BigPane";
                 });
             });
         });   
                 
         
          //ContactUs
          $('#btnCont').click(function(){
            if (currentView!="BigPane")
               { showOrangeContainer(false,function(){  document.getElementById("divAreas").style.display="none";});
                }
           else
           {   minimizeBigPane();
               document.getElementById("divAreas").style.display="none";
           }
           
            showOrangeContainer(true, function(){
            document.getElementById("btnX").style.display="block";
            var items = $("#divContact");
            document.getElementById("divContact").style.display="block";
            $('#divContact').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>'); 
            $('#divContact').load('contactUs.xml');
        });
           
    });
          
          
          
     
          
          //Facebook
          $('#socialFB').click(function(){
            if (currentView!="BigPane")
               { showOrangeContainer(false,function(){  document.getElementById("divAreas").style.display="none";});
                }
             else
               {   minimizeBigPane();
                   document.getElementById("divAreas").style.display="none";
               }
               showOrangeContainer(true, function(){
               document.getElementById("btnX").style.display="block";
               var items = $("#divContact");
               document.getElementById("divContact").style.display="block";
               $('#divContact').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>'); 
               $('#divContact').load('facebook.xml');
               });
           });
          
          
          
          //Twitter
          $('#socialTW').click(function(){
            if (currentView!="BigPane")
               { showOrangeContainer(false,function(){  document.getElementById("divAreas").style.display="none";});
                }
             else
               {   minimizeBigPane();
                   document.getElementById("divAreas").style.display="none";
               }
               showOrangeContainer(true, function(){
               document.getElementById("btnX").style.display="block";
               var items = $("#divContact");
               document.getElementById("divContact").style.display="block";
               $('#divContact').html('<img src="img/loading.gif" style="margin-left:300px; margin-top:66px;"/>'); 
               $('#divContact').load('twitter.xml');
               });
           });
     
     
          //Close lower Orange
          $('#btnX').click(function(){
               if (currentView!="BigPane")
               {
               showOrangeContainer(false,function(){ 
                  showOrangeContainer(true, function(){
               var items = $("#orangeSliderContent .medium_thumbs_list li");
               for(var i = 0; i < items.length; i++){
                $(items[i]).delay(i*200).animate({'padding-left':0},speed*1000);
               }
                 document.getElementById("divAreas").style.display="block";
               
               });
                                 document.getElementById("divContact").style.display="none";
                                 document.getElementById("btnX").style.display="none";

                                   });
               }
               else
               { showOrangeContainer(false,function(){restoreBigPane()});  }
               
                });
          
    
    
    
	
	$('#btnBack').click(function(){  
		//document.getElementById('btnBack').innerHTML="";
		showBigBarContainer(false, '',function(){
			showOrangeContainer(true, function(){
				showBlueContainer(true); document.getElementById("divAreas").style.display="block";   
                                var items = $("#orangeSliderContent .medium_thumbs_list li");            
            for(var i = 0; i < items.length; i++){
                $(items[i]).delay(i*200).animate({'padding-left':0},speed*1000);
            }
			})
		})
           showOrangeContainer(false,function(){  document.getElementById("divContact").style.display="none";
                               document.getElementById("btnX").style.display="none";
                                    restoreBigPane();
                               });
 
    });
    
    
    $('.thumb_medium').hover(function(){
        $(this).find('img.on').fadeIn(500);
    }, function(){
        $(this).find('img.on').fadeOut(500);
    });
});