


var parentPanel= null;
var paddingPanel= null;
var currentPanel = null;
var currentPanelID = "";
var currentPanelX = 0;
var currentPanelY = 0;
var docPadding = 30;

var clientScrollerHeight = 600;
var clientsWidth = 900;
var clientCurrent = 0;
var clientNumber = 3;


function positionMain(){

    $('#container').css('height',$(window).height()+"px");								
    $("div#pages").css("left", "-"+(currentPanelX-1)* $(window).width() + "px").css("top", "-"+(currentPanelY-1)* $(window).height() + "px");
    var tempPaddingHeight = $(window).height()-(docPadding*2);
    $("div#pages div.padding").css("height", tempPaddingHeight + "px")
    if(tempPaddingHeight >400){
        $("div#clientScroller").css("marginTop", ((tempPaddingHeight/2)-(clientScrollerHeight/2)) + "px")
    }else{
        $("div#clientScroller").css("marginTop", "0")
    }
	resetScroller();
}



function moveToPanel(panelID){
    
       
    if(currentPanelID !=panelID){
    
    parentPanel = $("body").find("div#"+panelID).eq(0);
    var xNum = parseInt($(parentPanel).attr("toX"));
    var yNum = parseInt($(parentPanel).attr("toY"));
    
    paddingPanel = $(parentPanel).find("div.padding").eq(0);
    currentPanel = $(parentPanel).find("div.content").eq(0);
  
    $(currentPanel).css("top", "0");
    currentPanelID = panelID;
    currentPanelX = xNum;
    currentPanelY = yNum;
    
    $("div#scroller").stop();
    $("div#pages").stop();
    
    var speedX = Math.abs((parseInt($("div#pages").css("left"))*(-.01)+1)-xNum)*200;
    var speedY = Math.abs((parseInt($("div#pages").css("top"))*(-.01)+1)-yNum)*200;
    var speedTotal = Math.sqrt((speedX*speedX)+(speedY*speedY));
 
    var newX = "0";
    var newY = "0";
    if(xNum>1){
        newX = "-"+(xNum-1)* $(window).width() + "px";
    }
    if(yNum>1){
        newY = "-"+(yNum-1)* $(window).height() + "px";
    }
    if($("div#scroller").css("display") != "none"){
        $("div#scroller").fadeOut("medium");
    }
    
    
   $("div#pages").animate({ 
                left: newX,
                top: newY
              },{ duration: 750, easing: "easeOutQuint", complete: resetScroller});
    }
}

$(window).resize(function(){
	positionMain();
});



$(document).ready(function(){

    fillWithLipsum();
    $("a.linkToPanel").bind("click", function(){
        panelLinkClick(this);
    });
    $("div#menu").css("opacity", .5);
    $("div#menulinks").bind("mouseenter", function(){
        $("div#menu").stop();
        $("div#menu").animate({ 
        opacity: .9
      }, 300 );
    });
    $("div#menulinks").bind("mouseleave", function(){
        $("div#menu").stop();
        $("div#menu").animate({ 
        opacity: .5
      }, { duration: 300, complete:function(){$("div#menulabel").css("display", "none");} } );
      
      $("div#menulabel").animate({ 
            opacity: .01
          }, 300 );
    });
    $("div#menulinks a").bind("click", function(){
        $("div#menulinks a").removeClass("active");
        $(this).addClass("active");
    });
    
    $("div#menulinks a").bind("mouseenter", function(){
        $("div#menulabel").stop();
        $("div#menulabel").css("display", "block").css("opacity", .01);
        $("div#menulabel").text($(this).attr("label"));   
        $("div#menulabel").animate({ 
            opacity: 1
          }, { duration: 300 });
    });
    $("a#clientScrollLeft").css("display", "none");
    $("a#clientScrollLeft").click(function(){
        if(clientCurrent>0){
            $("a#clientScrollRight").css("display", "block");
            clientCurrent--;
            var newX = (clientCurrent * clientsWidth * -1) + "px"
            $("div#clientsWrap").stop().animate({ 
                left: newX
              },{ duration: 250, easing: "easeOutQuint"});
        }
        if(clientCurrent<=0){
            $(this).css("display", "none");
        }
    });
    $("a#clientScrollRight").click(function(){
        if((clientCurrent+1)<clientNumber){
            $("a#clientScrollLeft").css("display", "block");
            clientCurrent++;
            var newX = (clientCurrent * clientsWidth * -1) + "px"
            $("div#clientsWrap").stop().animate({ 
                left: newX
              },{ duration: 250, easing: "easeOutQuint"});
        }
        if((clientCurrent+1)>=clientNumber){
            $(this).css("display", "none");
        }
    });

    $("a.fade").mouseover(function(){
        $(this).stop();
        $(this).animate({ 
            color: "#6CD913"
          }, 300 );
   }).mouseout(function(){
        $(this).stop();
        $(this).animate({ 
           color: "#818181"
         }, 300 );
   });
    
    
    panelLinkClick($("a#link5"));
    
    $("body").mouseup(function(){
        
    });
    
    $("div#scrollbar").mousedown(function(e){
        initDrag(e);
    });
    positionMain();
    
});
var mouseDiff;


function initDrag(event){
    mouseDiff = getPos(event, 'Y') - parseInt($("div#scrollbar").css("top"));
    jQuery('html').bind('mouseup',stopDrag).bind('mouseleave',stopDrag).bind('mousemove', startDragging);
};

function startDragging(event){
    var tempY = getPos(event, 'Y') - mouseDiff;
    var tempPercent = tempY/($("div#scroller").height()-$("div#scrollbar").height());
    if(tempPercent>1) tempPercent = 1;
    if(tempPercent<0) tempPercent = 0;
    tempY = ($("div#scroller").height()-$("div#scrollbar").height())*tempPercent;
    $("div#scrollbar").css("top", tempY  + "px");
    barScrollContent(tempPercent);
};
function stopDrag(event){
    jQuery('html').unbind('mousemove', startDragging);
};
var getPos = function (event, c) {
					var p = c == 'X' ? 'Left' : 'Top';
					return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
				};
				
function panelLinkClick(target){
        moveToPanel($(target).attr("panel"));
        if($(target).attr("changeMenuTo")!="" && $(target).attr("changeMenuTo")!=undefined){
             $("div#menu a").removeClass("active");
             $($(target).attr("changeMenuTo")).addClass("active");
        }
}

function resetScroller(){
 
        $("div#scroller").stop();
    if(currentPanel){
	    scrollerHeight = $("div#scroller").height();
        scrollbarHeight = ($(paddingPanel).height()/$(currentPanel).height())*scrollerHeight;
	    $("div#scrollbar").css("height", scrollbarHeight+"px").css("top", "0");
	}
	
	if ($("#container").unmousewheel) {$("#container").unmousewheel();}
	if(scrollerHeight>=scrollbarHeight && $(currentPanel).hasClass("noscroll")==false){
	
        $("div#scroller").css("opacity",1);
	    $("div#scroller").fadeIn();
        $("#container").mousewheel(
                function (event, d) {
	                mouseScrollContent(d*20);
	                return false;
                }
	    );
	    $("div#scrollbar").css("top", ((parseInt($(currentPanel).css("top"))/($(currentPanel).height()-$(paddingPanel).height())) * ($("div#scroller").height() - $("div#scrollbar").height()) * -1) + "px");
	}else{
	    $("div#scroller").fadeOut();
	}
	
}

function barScrollContent(a){
   if(currentPanel){
    var tempY = 0-($(currentPanel).height() - $(paddingPanel).height()) * a;
    $(currentPanel).css("top", tempY+"px");
   }
}

function mouseScrollContent(a){
   if(currentPanel){
        var tempY = parseInt($(currentPanel).css("top"))+a;
        if(tempY>0)tempY = 0;
        if(tempY<(0-$(currentPanel).height()+$(paddingPanel).height())) tempY = 0-$(currentPanel).height()+$(paddingPanel).height();
        $(currentPanel).css("top", tempY+"px");
        tempY = (tempY/($(currentPanel).height()-$(paddingPanel).height())) * ($("div#scroller").height() - $("div#scrollbar").height()) * -1;
        $("#debug").prepend(tempY + "<br />");
        $("div#scrollbar").css("top", tempY  + "px");
   
   }
}



function fillWithLipsum(){
    var lipsum = "<span style='color:#818181;'> Performance marketing. Lead Generation. Search Engine Optimization. Advertising. Internet Marketing. Web Design. Cost Per Acquisition. Web Design. Customer Relationship Management. Web 2.0. Insurance Marketing. Database Administration. Opt-in E-mail Campaigns. Ideas & Ingenuity. Creative Direction. Cost Per Sale. PHP. Software as a Service. User interaction. Marketing Strategy. Qualified Lead Development. Creative Writing. Sales Persuasion. Lead Capture. Publisher Development. Graphic Design. Specialty Financial Marketing. Increase Retention Rates. Outsourcing. Click-to-call. Lead Qualification. Web Application Development. Brand Management. Ruby on Rails. Compliance. Click-to-chat. Management Information Systems. IT Consulting. Search Engine Marketing. AJAX. Innovation. Pricing. Cost Per Click. White Papers. Copywriting. Logo Design. Financial Marketing. Online Conversions. Typography. Media Network Development. Logo Design. E-mail Management Systems. Blogs. Linux. Boosting LifeTime Value. Backoffice Management. Careers & Culture. Investment Marketing. Links. Apache Servers. Link Exchanges. Server Setup. Intelligent Marketing. Contact Us. Performance marketing. Lead Generation. Search Engine Optimization. Advertising. Internet Marketing. Web Design. Cost Per Acquisition. Web Design. Customer Relationship Management. Web 2.0. Insurance Marketing. Database Administration. Opt-in E-mail Campaigns. Ideas & Ingenuity. Creative Direction. Cost Per Sale. PHP. Software as a Service. User interaction. Marketing Strategy. Qualified Lead Development. Creative Writing. Sales Persuasion. Lead Capture. Publisher Development. Graphic Design. Specialty Financial Marketing. Increase Retention Rates. Outsourcing. Click-to-call. Lead Qualification. Web Application Development. Brand Management. Ruby on Rails. Compliance. Click-to-chat. Management Information Systems. IT Consulting. Search Engine Marketing. AJAX. Innovation. Pricing. Cost Per Click. White Papers. Copywriting. Logo Design. Financial Marketing. Online Conversions. Typography. Media Network Development. Logo Design. E-mail Management Systems. Blogs. Linux. Boosting LifeTime Value. Backoffice Management. Careers & Culture. Investment Marketing. Links. Apache Servers. Link Exchanges. Server Setup. Intelligent Marketing. Contact Us. Performance marketing. Lead Generation. Search Engine Optimization. Advertising. Internet Marketing. Web Design. Cost Per Acquisition. Web Design. Customer Relationship Management. Web 2.0. Insurance Marketing. Database Administration. Opt-in E-mail Campaigns. Ideas & Ingenuity. Creative Direction. Cost Per Sale. PHP. Software as a Service. User interaction. Marketing Strategy. Qualified Lead Development. Creative Writing. Sales Persuasion. Lead Capture. Publisher Development. Graphic Design. Specialty Financial Marketing. Increase Retention Rates. Outsourcing. Click-to-call. Lead Qualification. Web Application Development. Brand Management. Ruby on Rails. Compliance. Click-to-chat. Management Information Systems. IT Consulting. Search Engine Marketing. AJAX. Innovation. Pricing. Cost Per Click. White Papers. Copywriting. Logo Design. Financial Marketing. Online Conversions. Typography. Media Network Development. Logo Design. E-mail Management Systems. Blogs. Linux. Boosting LifeTime Value. Backoffice Management. Careers & Culture. Investment Marketing. Links. Apache Servers. Link Exchanges. Server Setup. Intelligent Marketing. Contact Us. Performance marketing. Lead Generation. Search Engine Optimization. Advertising. Internet Marketing. Web Design. Cost Per Acquisition. Web Design. Customer Relationship Management. Web 2.0. Insurance Marketing. Database Administration. Opt-in E-mail Campaigns. Ideas & Ingenuity. Creative Direction. Cost Per Sale. PHP. Software as a Service. User interaction. Marketing Strategy. Qualified Lead Development. Creative Writing. Sales Persuasion. Lead Capture. Publisher Development. Graphic Design. Specialty Financial Marketing. Increase Retention Rates. Outsourcing. Click-to-call. Lead Qualification. Web Application Development. Brand Management. Ruby on Rails. Compliance. Click-to-chat. Management Information Systems. IT Consulting. Search Engine Marketing. AJAX. Innovation. Pricing. Cost Per Click. White Papers. Copywriting. Logo Design. Financial Marketing. Online Conversions. Typography. Media Network Development. Logo Design. E-mail Management Systems. Blogs. Linux. Boosting LifeTime Value. Backoffice Management. Careers & Culture. Investment Marketing. Links. Apache Servers. Link Exchanges. Server Setup. Intelligent Marketing. Contact Us.</span>"
    
    $("div.filler").each(function(){
        var tempHtml = $(this).html();
        $(this).html(tempHtml+lipsum);
    })
    
}
