$(document).ready(function() 
{
	arrPageSizes  = ___getPageSize();
	arrPageScroll = ___getPageScroll();
	  
    $("#sliderWrap").animate({top: arrPageScroll[1] + ((arrPageSizes[3]-180) / 2)}, 10);
	  
	$("#openCloseIdentifier").hide();
	$("#buttonIdentifier").hide();
	
	$("#slider-mail").click( function(){
		Open('#slider-mail', $(this).attr('class'));
	}); 
	
	$("#slider-survey").click( function(){
		Open('#slider-survey', $(this).attr('class'));
	});	
	
	$("#slider-weblink").click( function(){
		Open('#slider-weblink', $(this).attr('class'));
	});
	
	$("#slider-twitter").click( function(){
		Open('#slider-twitter', $(this).attr('class'));
	});
        $("#slider-facebook").click(function(){
                Open('#slider-facebook', $(this).attr('class'));
        });
	
	$("#slider-news").click( function(){
		Open('#slider-news', $(this).attr('class'));
	});	
	
	
	$(window).scroll(function () {
							   
	  arrPageSizes  = ___getPageSize();
	  arrPageScroll = ___getPageScroll();

      $("#sliderWrap").animate({top: arrPageScroll[1] + ((arrPageSizes[3]-180) / 2)}, 10);
    });	
	
	
	$(window).resize(function () {
							   
	  arrPageSizes  = ___getPageSize();
	  arrPageScroll = ___getPageScroll();
	  
      $("#sliderWrap").animate({top: arrPageScroll[1] + ((arrPageSizes[3]-180) / 2)}, 10);
    });
	
	var mail = 0;
	var surv = 0;
	var webl = 0;
	var twit = 0;
	var rssr = 0;
        //var face = 0;
	
	//
	$("#slider-mail").mouseover( function()
	{	
		if (mail == 1)
			return;
		mail = 1;
		
		if($("#openCloseIdentifier").is(":hidden"))
		{		
			$("#hint-mail").show();
			$("#hint-mail").css({ top: $("#slider-mail").offset().top });
			$("#hint-mail").animate({ left: 30, opacity: 1 }).fadeIn();
		}
	});
	
	$("#slider-mail").mouseout( function()
	{
		$("#hint-mail").animate({ left: 250, opacity: 0 }, function(){ mail = 0;  $(this).hide(); });
	});	

	//
	$("#slider-survey").mouseover( function()
	{
		if (surv == 1)
			return;
		surv = 1;
		
		if($("#openCloseIdentifier").is(":hidden"))
		{		
			$("#hint-survey").show();
			$("#hint-survey").css({ top: $("#slider-survey").offset().top });
			$("#hint-survey").animate({ left: 30, opacity: 1 }).fadeIn();
		}
	});
	
	$("#slider-survey").mouseout( function()
	{
		$("#hint-survey").animate({ left: 250, opacity: 0 }, function(){surv = 0; $("#hint-survey").hide();});
	});	
	
	//
	$("#slider-weblink").mouseover( function()
	{
		if (webl == 1)
			return;
		webl = 1;
		
		if($("#openCloseIdentifier").is(":hidden"))
		{		
			$("#hint-download").show();
			$("#hint-download").css({ top: $("#slider-weblink").offset().top });
			$("#hint-download").animate({ left: 30, opacity: 1 }).fadeIn();
		}

	});
	
	$("#slider-weblink").mouseout( function()
	{
		$("#hint-download").animate({ left: 250, opacity: 0 }, function(){ webl = 0; $("#hint-download").hide();});
	});	
	
	//
	$("#slider-twitter").mouseover( function()
	{
		if (twit == 1)
			return;
		twit = 1;
		
		if($("#openCloseIdentifier").is(":hidden"))
		{		
			$("#hint-twitter").show();
			$("#hint-twitter").css({ top: $("#slider-twitter").offset().top });
			$("#hint-twitter").animate({ left: 30, opacity: 1 }).fadeIn();
		}
	});
	
	$("#slider-twitter").mouseout( function()
	{
		$("#hint-twitter").animate({ left: 250, opacity: 0 }, function(){twit = 0; $("#hint-twitter").hide();});
	});
        
        $("#slider-facebook").mouseover( function()
	{
		if (face == 1)
			return;
		face = 1;

		if($("#openCloseIdentifier").is(":hidden"))
		{
			$("#hint-facebook").show();
			$("#hint-facebook").css({ top: $("#slider-facebook").offset().top });
			$("#hint-facebook").animate({ left: 30, opacity: 1 }).fadeIn();
		}
	});

	$("#slider-facebook").mouseout( function()
	{
		$("#hint-facebook").animate({ left: 250, opacity: 0 }, function(){face = 0; $("#hint-facebook").hide();});
	});


	
	//
	$("#slider-news").mouseover( function()
	{
		if (rssr == 1)
			return;
		rssr = 1;

		if($("#openCloseIdentifier").is(":hidden"))
		{
			$("#hint-rss").show();
			$("#hint-rss").css({ top: $("#slider-news").offset().top });
			$("#hint-rss").animate({ left: 30, opacity: 1 }).fadeIn();
		}
	});
	
	$("#slider-news").mouseout( function()
	{
		$("#hint-rss").animate({ left: 250, opacity: 0 }, function(){rssr = 0; $("#hint-rss").hide(); });
	});		
});

function Open(button, langCode)
{
	if($("#openCloseIdentifier").is(":hidden"))
	{
		$("#hint-mail").hide();
		$("#hint-survey").hide();
		$("#hint-weblink").hide();
		$("#hint-twitter").hide();
               // $("#hint-facebook").hide();
		$("#hint-rss").hide();

		$("#slider").animate({marginLeft: "270px"}, 200);
		$("#openCloseIdentifier").show();
		Load(button, langCode);
	}	
}

$("#toolbar_close").live('click', function()
{
	$("#slider").animate({marginLeft: "-52px"}, 200 , function(){$("#openCloseIdentifier").hide();} );
	
});


function Load(button, langCode)
{
	$("#slider-content").html('<table width="317px" height="207px" border="0" cellspacing="0" cellpadding="0"><tr valign="middle"><td align="center"><img src="'+config_site_path+'images/loading.gif" /></td></tr></table>');
							  
	switch(button)
	{
		case '#slider-mail':
		{
			$("#slider-content").load(config_site_path+'ajax/email.php', {langCode:langCode},
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#register").css('opacity','0');
						 $("#register").animate({opacity: 1});
					}
					});
		}
		break;
	
		case '#slider-survey':
		{
			$("#slider-content").load(config_site_path+'ajax/survey.php', {langCode:langCode},
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#survey").css('opacity','0');
						 $("#survey").animate({opacity: 1});
					}
					});
		}
		break;	
	
		case '#slider-weblink':
		{
			$("#slider-content").load(config_site_path+'ajax/weblink.php', {langCode:langCode},
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#download").css('opacity','0');
						 $("#download").animate({opacity: 1});
					}
					});
		}
		break;	
	
		case '#slider-twitter':
		{
			$("#slider-content").load(config_site_path+'ajax/twitter.php', 
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#twitter").css('opacity','0');
						 $("#twitter").animate({opacity: 1});
					}
					});
		}
		break;

                case '#slider-facebook':
		{
			$("#slider-content").load(config_site_path+'ajax/facebook.php',
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#facebook").css('opacity','0');
						 $("#facebook").animate({opacity: 1});
					}
					});
		}
		break;
		
		case '#slider-news':
		{
			$("#slider-content").load(config_site_path+'ajax/rss.php', {langCode:langCode},
				function(response, status, xhr){
					if(status != 'error')
					{
						 $("#news").css('opacity','0');
						 $("#news").animate({opacity: 1});
					}
					});
		}
		break;		
	}
}


function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
