var activePage = 0;
var contentVisible = 1;
var currentWindowWidth = null;

$(document).ready(resize);
$(window).resize(resize);

function resize() {
	currentWindowWidth = $(window).width();
	globalContentWidth = $("#globalContent").width();
	menuWidth = $("#menu").width();
	
	$("#menu").css('left', (currentWindowWidth - menuWidth) / 2);
	$(".footer1").css('margin-left', (currentWindowWidth - 900) / 2);
	$("#dotpayContent").css('left', (currentWindowWidth - 390) / 2);
	
	if($(".kwota").val() > 0) { 
    $(".footer").css("top", 1750);
    ShowLogo();
  } else {
    $("#bumerangLogo").fadeOut(1, function() {});
  }
  
	$("#rightCorner").css('left', currentWindowWidth - 441);
	$("#globalContent").css('left', currentWindowWidth - globalContentWidth);
	$("#globalContent").css('margin-left', currentWindowWidth - (currentWindowWidth / 2) - 620);
	$("#zakonczenieContent").css('left', currentWindowWidth - (currentWindowWidth / 2) - 290);
} 

function ShowLogo() {
  $("#bumerangLogo").fadeIn(100, function() {});
  $("#bumerangLogo").css('z-index', 999999);
  $("#bumerangLogo").animate({ left: 0 }, 1000, function() {});
  $("#zakonczenieContent").fadeOut('fast');
}

function HideLogo() {
  $("#bumerangLogo").animate({ left: 3000 }, 1000, function() {});
  $("#bumerangLogo").fadeOut(100, function() {});
  $("#zakonczenieContent").fadeOut('fast');
}

function ShowSubMenu() {
  $("#submenu").animate({ left: 0 }, 100, function() {});
  $("#submenu").fadeIn('slow', function() {});
}

function HideSubMenu() {
  $("#submenu").fadeOut('fast', function() {});
}

function ShadowBGShow() {
  $("#blackbg").fadeIn(1000, function() {
  });
}

function fadeO(id, vName, shadow) {
  $(id).fadeOut('fast', function() {
    if(shadow == 1) {
      ShadowBGShow();
    }
    switch(vName)
    {
            case "konferencja": 
              okonferencji();
            break;
            case "mowcy": 
              if(contentVisible == 1) {
                $("#content").fadeOut(800, function() {
                  contentVisible = 0;
                });
              }
              ShowLogo();
              gary();
            break;
            case "gary": 
              garyVideo();
            break;
            case "gary2": 
              garyVideo2();
            break;
            case "nick": 
              nickVideo();
            break;
            case "robert": 
              robertVideo();
            break;
            case "tomasz": 
              tomaszVideo();
            break;
            case "miejsce":
              miejsce();
            break;
            case "program":
              program();
            break;
            case "rejestracja":
              rejestracja();
            break;
            case "koncert":
              koncert();
            break;              
    }
  });
}

function fadeI(id, vName) {
  $(id).fadeOut('fast', function() {
    
    $("#blackbg").fadeOut(1000, function() {});
    
    switch(activePage)
    {
      case 9: 
        gary();
      break;
      case 11: 
        nick();
      break;
      case 10: 
        robert();
      break;
      case 13: 
        tomasz();
      break;
    }
    
    $(id).fadeIn('fast', function() {});
    
  });
}

function ShadowBGHide(v) {
  switch(activePage)
  {
    case 9: 
      gary();
    break;
    case 11: 
      nick();
    break;
    case 10: 
      robert();
    break;
    case 13: 
      tomasz();
    break;
  }
  $("#blackbg").fadeOut(1000, function() {
  });
}

// O konferencji
function okonferencji() {
  HideSubMenu();
  $(".okonferencji").addClass("selected");
  $(".mowcy, .program, .miejsce, .rejestracja").removeClass("selected");
  if(activePage != 1) {
    ShowLogo();
    activePage = 1;
    $("#slideContent").css("left", 0);
    $("#slideContent").fadeIn(500, function() {});
  }
  // Content Disapear
  if(contentVisible == 1) {
    $("#content").fadeOut(800, function() {
      contentVisible = 0;
    });
  }
  $(".footer").css("top", 800);
}

// Miejsce
function program() {
  HideSubMenu();
  $(".program").addClass("selected");
  $(".miejsce, .mowcy, .okonferencji, .rejestracja").removeClass("selected");
  if(activePage != 15) {
    ShowLogo();
    activePage = 15;
    $("#slideContent").css("left", -17800);
    $("#slideContent").fadeIn(500, function() {});
  }
  // Content Disapear
  if(contentVisible == 1) {
    $("#content").fadeOut(800, function() {
      contentVisible = 0;
    });
  }
  $(".footer").css("top", 970);
}

// Miejsce
function miejsce() {
  HideSubMenu();
  $(".miejsce").addClass("selected");
  $(".mowcy, .program, .okonferencji, .rejestracja").removeClass("selected");
  if(activePage != 3) {
    ShowLogo();
    activePage = 3;
    $("#slideContent").css("left", -16500);
    $("#slideContent").fadeIn(500, function() {});
  }
  // Content Disapear
  if(contentVisible == 1) {
    $("#content").fadeOut(800, function() {
      contentVisible = 0;
    });
  }
  $(".footer").css("top", 700);
}

function rejestracja() {
  HideSubMenu();
  $(".rejestracja").addClass("selected");
  $(".mowcy, .program, .miejsce, .okonferencji").removeClass("selected");
  if(activePage != 4) {
    ShowLogo();
    activePage = 4;
    $("#slideContent").css("left", -19500);
    $("#slideContent").fadeIn(500, function() {});
  }
  $("#slideContent").css("height", 1900);
  // Content Disapear
  if(contentVisible == 1) {
    $("#content").fadeOut(800, function() {
      contentVisible = 0;
    });
  }
  $(".footer").css("top", 1500);
}

function gary() {
  $(".gary, .mowcy").addClass("selected");
  $(".tomasz, .program, .robert, .nick, .okonferencji, .miejsce, .rejestracja").removeClass("selected");
  if(activePage != 6) {
    ShowSubMenu();
    activePage = 6;
    $("#slideContent").animate({left: -1750}, 600, function() {});
    $("#slideContent").fadeIn(500, function() {});
  }
  $(".footer").css("top", 900);
}

function robert() {
  $(".robert").addClass("selected");
  $(".nick, .gary, .tomasz").removeClass("selected");
  if(activePage != 7) {
    $("#slideContent").animate({left: -3150}, 600, function() {});
    activePage = 7;
  }
}

function nick() {
  if(activePage != 8) {
    $("#slideContent").animate({left: -5950}, 600, function() {});
    activePage = 8;
  }
  $(".nick").addClass("selected");
  $(".robert, .gary, .tomasz").removeClass("selected");
}

function tomasz() {
  if(activePage != 14) {
    $("#slideContent").animate({left: -4550}, 600, function() {});
    activePage = 14;
  }
  $(".tomasz").addClass("selected");
  $(".nick, .robert, .gary").removeClass("selected");
}

// Videos
function garyVideo() {
  if(activePage != 9) {
    $("#slideContent").css("left", -7110);
    activePage = 9;
    
    $("#slideContent").fadeIn('fast', function() {});  
  }
  ShadowBGShow();
}

function garyVideo2() {
  if(activePage != 9) {
    $("#slideContent").css("left", -14710);
    activePage = 9;
    
    $("#slideContent").fadeIn('fast', function() {});  
  }
  ShadowBGShow();
}

function robertVideo() {
  if(activePage != 10) {
    $("#slideContent").css("left", -9010);
    activePage = 10;
    
    $("#slideContent").fadeIn('fast', function() {}); 
  }
  ShadowBGShow();
}

function tomaszVideo() {
  if(activePage != 13) {
      $("#slideContent").css("left", -10910);
      activePage = 13;
      
      $("#slideContent").fadeIn('fast', function() {}); 
    }
  ShadowBGShow();
}


function nickVideo() {
  if(activePage != 11) {
      $("#slideContent").css("left", -12810);
      activePage = 11;
      
      $("#slideContent").fadeIn('fast', function() {}); 
    }
  ShadowBGShow();
}

function koncert() {
  $(".gary, .mowcy, .robert, .nick, .okonferencji, .miejsce, .rejestracja").removeClass("selected");
  HideSubMenu();
  if(activePage != 12) {
    ShowLogo();
    activePage = 12;
    $("#slideContent").css("left", -22450);
    $("#slideContent").fadeIn(500, function() {});
  }
  // Content Disapear
  if(contentVisible == 1) {
    $("#content").fadeOut(800, function() {
      contentVisible = 0;
    });
  }
  $(".footer").css("top", 800);
}  

// OnClick functions
$(".okonferencji").live('click', function(){
    fadeO("#slideContent", "konferencja", 0);
    if($(".okonferencji").is(".selected")) {  
  		return false;
  	} 
});
$(".mowcy").live('click', function(){
    fadeO("#slideContent", "mowcy", 0);
    if($(".mowcy").is(".selected")) {  
  		return false;
  	} ;
});
$(".miejsce").live('click', function(){
    fadeO("#slideContent", "miejsce", 0);
    if($(".miejsce").is(".selected")) {  
  		return false;
  	} 
});
$(".program").live('click', function(){
    fadeO("#slideContent", "program", 0);
    if($(".program").is(".selected")) {  
  		return false;
  	} 
});
$(".rejestracja").live('click', function(){
    fadeO("#slideContent", "rejestracja", 0);
    if($(".rejestracja").is(".selected")) {  
  		return false;
  	} 
});

// Submenu
$(".gary").live('click', function(){
  gary();
  if ($(".gary").is(".selected")) {  
		return false;
	} 
});
$(".robert").live('click', function(){
    robert();
  if ($(".robert").is(".selected")) {  
		return false; 
	}  
});
$(".nick").live('click', function(){
  nick();
  if ($(".nick").is(".selected")) {  
		return false; 
	}   
});
$(".tomasz").live('click', function(){
  tomasz();
  if ($(".tomasz").is(".selected")) {  
		return false; 
	}   
});
// Mowcy Videos
$(".garyVideo").live('click', function(){
  fadeO("#slideContent", "gary", 1);
  return false;
});

$(".garyVideo2").live('click', function(){
  fadeO("#slideContent", "gary2", 1);
  return false;
});

$(".robertVideo").live('click', function(){
  fadeO("#slideContent", "robert", 1);
  return false;
});

$(".nickVideo").live('click', function(){
  fadeO("#slideContent", "nick", 1);
  return false;
});

$(".tomaszVideo").live('click', function(){
  fadeO("#slideContent", "tomasz", 1);
  return false;
});

$("#rightCorner").live('click', function(){
  fadeO("#slideContent", "koncert", 0);
  return false;
});

$("#bumerangLogo").live('click', function(){
  HideLogo();
  $(".gary, .tomasz, .program, .mowcy, .robert, .nick, .okonferencji, .miejsce, .rejestracja").removeClass("selected");
  $("#slideContent").css("left", 3000);
  if(contentVisible == 0) {
    $("#content").fadeIn(800, function() {
      contentVisible = 1;
    });
  }
  return false;
});

$(".koncerthillsong").live('click', function(){
  fadeO("#slideContent", "koncert", 0);
  return false;
});