$(document).ready(function(){

var hostname = window.location.hostname;
var hostmaindir = "";
	$(".shell_context").load(".shell_context",'',showNewContent());
	
	function showNewContent() {
		$(".text_block").fadeIn("slow");
		}
		
var navigation = $("#navigation");
var calendar = $("#calendar");

var prevCal = $("#prevcal");
var nextCal = $("#nextcal");
var pageLang = getUrlVars()["3"];
var pageModule = getUrlVars()["m"];
var pageDay = "";

//alert(getUrlVars()[3]);
if(pageModule == "archive")
{
	//alert("Hello");
	var curr_date = getUrlVars()["day"];
	var curr_month = getUrlVars()["month"];
	var curr_year = getUrlVars()["year"];
}
else
{	
	var d = new Date();
	var curr_date = d.getDate();
	var curr_year = d.getFullYear();
	var curr_month = d.getMonth()+1;
	
	//alert(d.getFullYear());
}
//Get URL Vars(Parametrs)

//var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
//alert(hashes);
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('/') + 0).split('/');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('/');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }    
    return vars;
}
//Load Navigation Menu

  $('#menu_body li ul').hide();
  $('.cat_menu_main').click(function() {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
        
        }
      if((checkElement.is('ul')) && (!checkElement.is(':visible')) && (checkElement.text())) {
        $('#menu_body li ul:visible').slideUp('normal');
        checkElement.slideDown('normal');
        return false;
        }
  });

$('#menu_body li ul').each(function(){
    
    if(!$(this).is(':empty'))
    {
        //alert(this);
      $(this).prev().css('background-image', 'url(http://'+hostname+'/'+hostmaindir+'/template/default/images/button_arrow.png)');

            
      $(this).prev().mouseenter(function() {
      $(this).css('background-image', 'url(http://'+hostname+'/'+hostmaindir+'/template/default/images/button_arrow_down.png)');
      });

      $(this).prev().mouseleave(function() {
      $(this).css('background-image', 'url(http://'+hostname+'/'+hostmaindir+'/template/default/images/button_arrow.png)');
      });
    }
});


//----------------------------
/*

navigation.load("menu.php?l=" + pageLang,"", function(){
	//$("div.sub_menu").slideUp("slow");
	
	$('ul.menu li ul li div').click(
			function() {
	var link = $(this).attr("link");
	$("#content").load("modules/pages.php" + link +" #pages");
			});
	
	$('ul.menu ul').hide();
	$('ul.menu li div').click(
			function() {
			var link = $(this).attr("link");	
			if(link != "#")
			{
				$("#content").load("modules/pages.php" + link +" #pages");
			}
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;
			
			if($('#' + parent).hasClass('noaccordion')) {
			$(this).next().slideToggle('normal');
			return false;
			}
			if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			if($('#' + parent).hasClass('collapsible')) {
			$('#' + parent + ' ul:visible').slideUp('normal');
			}
			return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#' + parent + ' ul:visible').slideUp('normal');
			checkElement.slideDown('normal');
			return false;
			}	
			
			
			}
			); 
	//$(".sub_menu").hide();
	/*$(".cat_menu").click(function()
			{
				var parent = $(this);
				var child = $(".sub_menu",this);
				//$(".sub_menu",this).css('background-color','red').slideDown(500);
				//$(".sub_menu",this).appendTo(".sub_menu_platform:first").css('background-color','red').slideDown(500);
				//$(this).css('background-color','red');
				if(($(".cat_menu").is('div')) && ($(".sub_menu").is(':visible'))) {		
					$(".sub_menu").slideUp('normal');
					child.css('background-color','red').slideDown(500);
					return false;
				}
				if((parent.is('div')) && (!$(".sub_menu").is(':visible'))) {
					child.css('background-color','red').slideDown(500);
					return false;
					}

			});

	
});*/
//Load Calendar
calendar.load("http://"+hostname+"/"+hostmaindir+"/calendar.php?l=" + pageLang + "&day=" + pageDay + "&month=" + curr_month + "&year=" + curr_year + " #calendar_table","",function(){
	prevCal.fadeIn("slow");
	nextCal.fadeIn("slow");
	showCalendar();
	
	/*
	var sel_day = $(".sel_day");
	//alert(link);
	//content.text(title);
	sel_day.click(function(){
		//$("#content").css("border","3px solid red");
		var link = $(this).attr("link");
		$("#content").load("http://localhost/modules/archive.php" + link +" #archive");
	});*/
});

function showCalendar() {
	$(".calendar").fadeIn("fast",hideLoader());
	}

function hideLoader() {
	$('#loader').fadeOut('normal');
	} 
//----------------------------

//Previously Month
prevCal.click(function(){
	//var curr_year = 2009;
	curr_month--;
	if(curr_month < 1)
	{
		curr_month = 12
		curr_year--;
	}
	//alert(curr_month);
	calendar.load("http://"+hostname+"/"+hostmaindir+"/calendar.php?l=" + pageLang + "&day=" + pageDay + "&month=" + curr_month + "&year=" + curr_year + " #calendar_table","",function(){
		showCalendar();
/*
		var sel_day = $(".sel_day");
		sel_day.click(function(){
			var link = $(this).attr("link");
			$("#calendar_table").load("http://localhost/modules/archive.php" + link +" #archive");
		});*/
	});	
});
//----------------------------

//Next Month
nextCal.click(function(){
	curr_month++;
	if(curr_month > 12)
	{
		curr_month = 1
		curr_year++;
	}
	calendar.load("http://"+hostname+"/"+hostmaindir+"/calendar.php?l=" + pageLang + "&day=" + pageDay + "&month=" + curr_month + "&year=" + curr_year + " #calendar_table","",function(){
		showCalendar();
                /*
		var sel_day = $(".sel_day");
		sel_day.click(function(){
			var link = $(this).attr("link");
			$("#calendar_table").load("http://localhost/modules/archive.php" + link +" #archive");
		});*/
	});	
});
//----------------------------


return false; 
});

