function DrawBackground() {
	$(".boxholder").backgroundCanvasPaint(Demo1BackgroundPaintFkt);
//	$("#Demo2Container").backgroundCanvasPaint(Demo2BackgroundPaintFkt); 

}

function Demo1BackgroundPaintFkt(context, width, height, canvas, $canvas, $canvasDiv, $content, $element ) {
		var options = {x:0, height: height, width: width, radius:15,  border: 0 };
		var backgroundGradient = context.createLinearGradient(0, 0, 0, height - 2);
		backgroundGradient.addColorStop(0 ,'#004400');
		backgroundGradient.addColorStop(1, '#002200');
		
		context.fillStyle = "#00cc00";
		$.canvasPaint.roundedRect(context,options);
		
		options.border = 1;
		context.fillStyle = backgroundGradient; 
		$.canvasPaint.roundedRect(context,options);
		
		var optionsA = {x:10,y:10, height: (height-20), width: (width-20), radius:10,  border: 0 };
		context.fillStyle = "#00cc00";
		$.canvasPaint.roundedRect(context,optionsA);
		var optionsA = {x:11,y:11, height: (height-22), width: (width-22), radius:9,  border: 0 };
		context.fillStyle = "#000000";
		$.canvasPaint.roundedRect(context,optionsA);
}



var GB_ANIMATION = true;
var lori = "START In sem justo, commodo ut, suscipit at, pharetra vitae, orci. Duis sapien nunc, commodo et, interdum suscipit, sollicitudin et, dolor. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aliquam id dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Mauris dictum facilisis augue. Fusce tellus. Pellentesque arcu. Maecenas fermentum, sem in pharetra pellentesque, velit turpis volutpat ante, in pharetra metus odio a lectus. Sed elit dui, pellentesque a, faucibus vel, interdum nec, diam. Mauris dolor felis, sagittis at, luctus sed, aliquam non, tellus. Etiam ligula pede, sagittis quis, interdum ultricies, Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi gravida libero nec velit. Morbi scelerisque luctus velit. Etiam dui sem, fermentum vitae, sagittis id, malesuada in, quam. Proin mattis lacinia justo. Vestibulum facilisis auctor urna. Aliquam in lorem sit amet leo accumsan lacinia. Integer rutrum, orci vestibulum ullamcorper ultricies, lacus quam ultricies odio, vitae placerat pede sem sit amet enim. Phasellus et lorem id felis nonummy placerat. Fusce dui leo, imperdiet in, aliquam sit amet, feugiat eu, orci. Aenean vel massa quis mauris vehicula lacinia. Quisque tincidunt scelerisque libero. Maecenas libero. Etiam dictum tincidunt diam. Donec ipsum massa, ullamcorper in, Morbi leo mi, nonummy eget, tristique non, rhoncus non, leo. Nullam faucibus mi quis velit. Integer in sapien. Fusce tellus odio, dapibus id, fermentum quis, suscipit id, erat. Fusce aliquam vestibulum ipsum. Aliquam erat volutpat. Pellentesque sapien. Cras elementum. Nulla pulvinar eleifend sem. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque porta. Vivamus porttitor turpis ac leo. Maecenas ipsum velit, consectetuer eu, lobortis ut, dictum at, dui. In rutrum. Sed ac dolor sit amet purus malesuada congue. In laoreet, magna id viverra tincidunt, sem odio bibendum justo, vel imperdiet sapien wisi sed libero. Suspendisse sagittis ultrices END";
function handlemy(what,how){
  switch(what) {
    case "bdoors":
     var t_start = ((($(window).width()/2) - 1810)+7).toString()+"px";
     var t_end = "-1785px";
     switch(how) {
        case "open":
          $(".door_left").animate({ left: t_end },1000);
          $(".door_right").animate({ right: t_end },1000);
          setTimeout(function(){$(".door_left_teeth").css({backgroundColor: "transparent"})},10);
          break;
        case "shut":
          setTimeout(function(){$(".door_left_teeth").css({backgroundColor: "#000"})},990);
          $(".door_left").animate({ left: t_start },1000);
          $(".door_right").animate({ right: t_start },1000);
          break;
      }break;
    case "navbar":
      var n_start = (($(window).width() / 2) - 140).toString()+"px";
      var n_end = ($(window).width() - 90).toString()+"px";
      switch(how) {
        case "open":
          $(".t_nav_case").animate({paddingRight: n_start,paddingLeft: n_start},750);
          $(".t_nav_case").animate({opacity: 1},500).animate({width:n_end,paddingRight: "55px",paddingLeft: "35px"},1000);
          $(".t_nav_ul li").animate({opacity: 0},2000).animate({opacity: 1},1000);
          break;
        case "shut":
          $(".t_nav_case").animate({opacity: 1},750).animate({opacity: 1},1000).animate({paddingRight: "0",paddingLeft: "0"},500);
          $(".t_nav_case").animate({opacity: 1},750).animate({width: "260px",paddingRight: "0",paddingLeft: "0"},1000);
          $(".t_nav_ul li").animate({opacity: 0},750);
          break;
      }break;
    case "header":switch(how) {
        case "open":
          $(".logo").animate({top: '+=300px'},1000);
          $(".right_top_screen").animate({top: '+=300px'},1000).animate({right: '-=231px'},750);
          $(".left_top_screen").animate({top: '+=300px'},1000).animate({left: '-=231px'},750);
          $(".t_nav").animate({top: "+=300px"},2000);
          break;
        case "shut":
          $(".logo").animate({opacity: 1},750).animate({top: '-=300px'},1000);
          $(".right_top_screen").animate({right: '+=231px'},750).animate({top: '-=300px'},1000);
          $(".left_top_screen").animate({left: '+=231px'},750).animate({top: '-=300px'},1000);
          $(".t_nav").animate({opacity: 1},750).animate({top: "-=300px"},750);
          break;
      }break;
    case "bottom":switch(how) {
        case "open":
          $(".cover_foot").animate({width:0},500).animate({height:0},500);
          $(".foot_content").animate({height: "+=60px",paddingBottom:"+=10px",paddingTop:"+=30px"},500);
          break;
        case "shut":
          $(".foot_content").animate({opacity: 1},500).animate({height: "-=60",paddingBottom:"-=10px",paddingTop:"-=30px"},500);
          $(".cover_foot").animate({height: "+=100px"},500);
          break;
      }break;
    case "lazers":switch(how) {
        case "open":
          $(".lazer_case").animate({width: "-=220px",marginLeft: "+=110"}, 250);
          $(".cover_green_hbar").animate({opacity: 1},750).animate({width:0},1000);
          $(".page_title_left").animate({left: "+=300px"},750);
          $(".green_t_hbar").animate({opacity:0},750).animate({opacity: 1},1000);
          $(".content").animate({opacity:0},750).animate({width: "-=180px",marginLeft: "88px",marginRight: "92px"},1000).animate({opacity: 1},500);
          break;
       case "shut":
          $(".content").animate({height: window.c_start},750).animate({opacity:0},500);
          $(".cover_green_hbar").animate({opacity: 1},1250).animate({width: (screen.availWidth).toString()+"px"},1000);
          $(".lazer_case").animate({opacity: 1},2250).animate({marginLeft: "-=110px",width: "+=220px"}, 250);
          $(".page_title_left").animate({opacity: 1},2250).animate({left: "-=300px"},250);
          break;
      }break;
  }
}

function tracker_do(data, x, z){
  $(".cursorz").remove();
  $(".top_screen_l0").append("<div><span class=\"cursorz\">_</span></div>");
  $(".top_screen_l0 div:last").css({opacity:0});
  $(".top_screen_l0 div:last").animate({opacity:1},1000);
  if (x == 11) {
    data = "<a href=\'yes\' class=\'redotrak\'>Check Again?</a> ";
    clearTimeout(tracker_do);window.trackerun=0;
  }
  $(".cursorz").before(data);
  if (x == 3){//to make map link bind to the pop's
    $("a.pop").unbind("click");
    $("a.pop").click(function(){
      var t = this.title || this.title || this.href;
      var makeHeight = $(window).height() - 90;
      var makeWidth = $(window).width() - 120;
      GB_show(t,this.href,makeHeight,makeWidth);
      return false;}
    );
  } else if (x == 11) {
    $(".redotrak").click(function(){if(window.trackerun==0){run_tracker(0,4);window.trackerun=1}return false});
  }
  if (x <= 11) {
    x=x+1;
  } else {
    x=0;
  }
  if (z <= 3) {
    z=z+1;
  } else {
    $(".top_screen_l0 div:first").animate({opacity:0},500);
    setTimeout(function(){$(".top_screen_l0 div:first").remove()},500);
  }
  if (x <= 11) {setTimeout("run_tracker("+x+","+z+")",5000);}
}

function run_tracker(x, z) {
  switch(x) {
    case 0:var datasend = "mode=tracker&swich=hits";break;
    case 1:var datasend = "mode=tracker&swich=uhits";break;
    case 2:var datasend = "mode=tracker&swich=yip";break;
    case 3:var datasend = "mode=tracker&swich=mip";break;
    case 4:var datasend = "mode=tracker&swich=lang";break;
    case 5:var datasend = "mode=tracker&swich=os";break;
    case 6:var datasend = "mode=tracker&swich=browser";break;
    case 7:var datasend = "mode=humor";break;
    case 8:var datasend = "mode=humor1";break;
    case 9:var datasend = "mode=humor";break;
    case 10:var datasend = "mode=humor1";break;
    case 11:var datasend = "mode=humor1";break;
  }
  $.ajax({url: "backend.php",cache: "false",dataType: "html",processData: "false",type: "GET",
    data: datasend,
    success: function(data){tracker_do(data, x, z)},
    error: function(){tracker_do("Error: "+x.toString()+".", x, z)}
  });
}

function run_start() {
  setTimeout(function(){$(".cover_all").animate({opacity: 0},1000)},500);
  setTimeout("handlemy('bdoors','open')",1000);
  setTimeout("handlemy('header','open')",1500);
  setTimeout("handlemy('navbar','open')",3500);
  setTimeout("handlemy('bottom','open')",1500);
  setTimeout("handlemy('lazers','open')",2250);
  setTimeout(function(){$(".cover_all").css({zIndex: "-100",backgroundImage: "none"})},5750); //enable clicks @ 5.75 seconds
  setTimeout(function(){$(".content_wrapper").animate({opacity: 1},1000);},6000);
  setTimeout(function(){
        $.ajax({url: "backend.php",cache: "false",dataType: "html",processData: "false",type: "GET",
          data: "mode=page&swich=0",
          success: function(data){
            var title = data.slice(0,data.indexOf("*"));
            var body= data.slice(data.indexOf("*")+1);
            if(body.length <= 1){body=lori}
            $(".page_title_span h1").text(title);
            $(".content_wrapper").html(body);
            //to make map link bind to the pop's
            $("a.pop").unbind("click");
            $("a.pop").click(function(){
              var t = this.title || this.title || this.href;
              var makeHeight = $(window).height() - 90;
              var makeWidth = $(window).width() - 120;
              GB_show(t,this.href,makeHeight,makeWidth);
              return false;}
            );
            $(".showhide").toggle(
              function() {
                $(this).parent().parent().parent().parent().children("div.inner").show();
                $(this).text("hide");
                $(".shold li").css({listStyleType: "disc"});
                setTimeout("DrawBackground()",100);
              },
              function() {
                $(this).parent().parent().parent().parent().children("div.inner").hide();
                $(this).text("show");
                $(".shold li").css({listStyleType: "circle"});
                setTimeout("DrawBackground()",100);
              }
            );
            $(".showhide").parent().parent().parent().parent().children("div.inner").hide();
            setTimeout("DrawBackground()",100);
            $(".boxholder").backgroundCanvas();
            DrawBackground();
          }
        });},5000);
}

function run_close() {
  window.scrollBy(0,-10000);
  $(".cover_all").css({zIndex: "10",opacity:0}); //disable clicking after the sequence has started
  $(".content_wrapper").animate({opacity: 0},500);
  setTimeout("handlemy('lazers','shut')",750);
  setTimeout("handlemy('navbar','shut')",1250);
  setTimeout("handlemy('bottom','shut')",2500);
  setTimeout("handlemy('header','shut')",4000);    
  setTimeout("handlemy('bdoors','shut')",5750);
  setTimeout(function(){$(".cover_all").animate({opacity: 1},500)},6250);
}

function set_start() {
  window.c_start = ($(window).height() -490);
  window.c_height = $(".content").height();
  if (window.c_height < window.c_start) {
    window.c_height = window.c_start.toString()+"px";
  } else {
    window.c_height = window.c_height.toString()+"px";
  }
  if (window.c_start < 100) {
    window.c_start = "100px";
  } else {
    window.c_start = window.c_start.toString()+"px";
  }
  $(".content_wrapper").css({opacity: 0});
  var t_start = ((($(window).width()/2) - 1810)+7).toString()+"px";
  var s_start = (($(window).width()/2) - 258).toString()+"px";
  $(".door_left").css({ left: t_start });
  $(".door_right").css({ right: t_start });
  $(".left_top_screen").css({left: s_start});
  $(".right_top_screen").css({right: s_start});
  $(".lazer_case").width($(window).width()+220);
  $(".lazer_case").animate({marginLeft: "-110px"}, 0);
  $(".t_nav_ul li").css({opacity: 0});
  $(".page_title_left").animate({left: "-=300px"},0);
}

function ajax_open(waitamin) {
  setTimeout("handlemy('bdoors','open')",waitamin);
  waitamin=waitamin+1000;
  $(".content").animate({opacity:1},waitamin);
  waitamin=waitamin-500;
  $(".cover_all").animate({opacity: .5},waitamin).animate({opacity: 0},250); //enable clicks
  setTimeout(function(){$(".cover_all").css({zIndex: "-1"});},waitamin);
  setTimeout(function(){$(".content_wrapper").animate({opacity: 1},500);},waitamin);
  $(".boxholder").backgroundCanvas();
  DrawBackground();
}

$(window).load(function(){
  DrawBackground();
  if($(window).width() < 1000){
    window.resizeBy((1000 - $(window).width()),0);
  }
  if($(window).height() > 1100) {
    window.resizeBy(0,(1100 - $(window).height()));
  }
  setTimeout(function(){    
    $(window).resize(function () {
    DrawBackground();
      var soffset = $(".right_top_screen").offset();
      var loffset = $(".logo").offset();
      var n_start = (($(this).width() / 2) - 140).toString()+"px";
      if($(this).width() <= 1000) {
        $(".right_top_screen").css({left: "589px"});
        $(".left_top_screen").css({left: "11px"});
        $(".logo").css({margin: "0 255px 0 256px"});
        var n_end="910px";
        lazer_width=1000;
        content_width="820px";
      } else if ($(this).width() > 1000) {
        var n_end=($(this).width() - 90).toString()+"px";
        lazer_width=$(this).width();
        content_width=($(this).width() - 180).toString()+"px";
        var sa_start = (($(this).width()/2) -489).toString()+"px";
        $(".left_top_screen").css({left: sa_start});
        $(".logo").css({margin: "0 auto"});
        var sa_start = ((($(this).width()/2) -489)+578).toString()+"px";
        $(".right_top_screen").css({left: sa_start})
        if ($(".content").height() < parseInt(window.c_start.substr(0,(this.length-2)))) {
          $(".content").css({minHeight: window.c_start});
        }
      }
      $(".t_nav_case").css({paddingRight: n_start,paddingLeft: n_start});
      $(".t_nav_case").css({width:n_end,paddingRight: "55px",paddingLeft: "35px"});
      $(".lazer_case").width(lazer_width);
      $(".content").css({width: content_width,marginLeft: "88px",marginRight: "92px"});
      $(".foot").css({width: (lazer_width.toString()+"px")}); 
    });
  },5000);
  set_start();
  run_start();
  setTimeout("run_tracker(0,0)",7000);
});

$(document).ready(function() {
  $(".boxholder").backgroundCanvas();
  setInterval(function(){$(".cursorz").toggleClass("black")}, 500);
  $(".closer").click(
    function () {
      $(".content_wrapper").animate({opacity: 0},500);
      $(".cover_all").css({zIndex: "10",opacity:0}).animate({opacity: .5},500); //disable clicking after the sequence has started
      var waitamin = 1000;
     // window.scrollBy(0,-10000);
      setTimeout("handlemy('bdoors','shut')",750);
      if ($(this).attr('href')) {
        var datasend = "mode=page&swich="+($(this).attr('href')).charAt((this.length -1)).toString();
      }  else {
        var datasemd = "mode=page&swich=0";
      }
      setTimeout(function() {
        $.ajax({url: "backend.php",cache: "false",dataType: "html",processData: "false",type: "GET",
          data: datasend,
          error: function(){ajax_open(waitamin)},
          success: function(data){
            var title = data.slice(0,data.indexOf("*"));
            var body= data.slice(data.indexOf("*")+1);
            if(body.length <= 1){body=lori}
            $(".page_title_span h1").text(title);
            $(".content_wrapper").html(body);
            $(".showhide").toggle(
              function() {
                $(this).parent().parent().parent().parent().children("div.inner").show();
                $(this).text("hide");
                $(".shold li").css({listStyleType: "disc"});
                setTimeout("DrawBackground()",100);
              },
              function() {
                $(this).parent().parent().parent().parent().children("div.inner").hide();
                $(this).text("show");
                $(".shold li").css({listStyleType: "circle"});
                setTimeout("DrawBackground()",100);
              }
            );
            $(".showhide").parent().parent().parent().parent().children("div.inner").hide();
            setTimeout("DrawBackground()",100);
            ajax_open(waitamin)
          }
        });
      },waitamin);
      return false;
    }
  );

  $("a.pop").click(function(){
    var t = this.title || this.href;
    var makeHeight = $(window).height() - 90;
    var makeWidth = $(window).width() - 120;
    GB_show(t,this.href,makeHeight,makeWidth);
    return false;}
  );

  $(".specialForm").submit(function() {
    run_close();
    setTimeout(function() {$(".specialForm").unbind("submit");$(".specialForm").submit(); }, 6250); 
    return false;
  });
  
});
