// USED EXTERNAL VARIABLE:
//
// template_directory - variable is defined in head.php
//
////////////////////////////////////////////////////////////////

function unsubscribe() {
	//event.preventDefault();
	$('#wpsb_radio_option1').attr('checked', 'false');
	$('#wpsb_radio_option2').attr('checked', 'true');
	$('#register_nl').click();

};

function registracija_plus() {
	$('#imone').toggle();
	if ($("#reg_expand").attr('src') == template_directory+'/images/icon_expand.png') {
		$("#reg_expand").attr('src', template_directory+'/images/icon_minus.png');
	}
	else {
		$("#reg_expand").attr('src', template_directory+'/images/icon_expand.png');
		
	};

};


function update_calendar(date) {
	
	//$('.calendar').fadeOut();
	$.post(
		template_directory + "/ajax.php",
		{func: "get_calendar",
		 date: date},
		function(data){
			$("#calendar_holder").html(data); 
			
			coef = 7;
			// Calendar table bug:
			if ($.browser.mozilla) {
				$("#calendar_holder .calendar table").css({'margin': '1px 0 0 0'});
				coef = 8;
			}				
			
			$("#calendar_holder .prev_month").height($("#calendar_holder .calendar table").height()-coef);
			$("#calendar_holder .next_month").height($("#calendar_holder .calendar table").height()-coef);
			
			$("#calendar_holder .prev_month .middle p").css("padding-top", ($("#calendar_holder .calendar table").height()-28)/2);
			$("#calendar_holder .next_month .middle p").css("padding-top", ($("#calendar_holder .calendar table").height()-28)/2);
			

			 
			$('.calendar').fadeIn();
			setup_carousel('side_gallery');
		},
		"html"
	);
	
	
};


function update_big_calendar(date) {
	
	//$('.calendar').fadeOut();
	$.post(
		template_directory + "/ajax.php",
		{func: "get_big_calendar",
		 date: date},
		function(data){
		
			$("#big_calendar_holder").html(data); 
			
			coef = 7;
			// Calendar table bug:
			if ($.browser.mozilla) {
				$("#big_calendar_holder .big_calendar table").css({'margin': '1px 0 0 0'});
				coef = 8;
			}			
			
			
			$("#big_calendar_holder .prev_month").height($("#big_calendar_holder .big_calendar table").height()-coef);
			$("#big_calendar_holder .next_month").height($("#big_calendar_holder .big_calendar table").height()-coef);
			
			$("#big_calendar_holder .prev_month .middle p").css("padding-top", ($("#big_calendar_holder .big_calendar table").height()-28)/2);
			$("#big_calendar_holder .next_month .middle p").css("padding-top", ($("#big_calendar_holder .big_calendar table").height()-28)/2);
			
			$('#big_calendar_holder .calendar').fadeIn();


			
		},
		"html"
	);
	
	
};


function get_mn_post(category, offset) {
	//$('<div id="LoginWithAjax_Loading"></div>').prependTo('#news_panel');
	$('#news_panel').fadeTo(600, 0.1);
	$.post(
		template_directory + "/ajax.php",
		{func: "get_mainnews",
		 offset: offset,
		 cat: category},
		function(data){
			$("#news_panel").html(data);
			$('#news_panel').fadeTo(200, 1);
			setup_carousel('mygallery');
			
			$("#first_news_buttons a").removeClass("current");
			
			id = '#g'+ offset;
			$(id).addClass('current');
			
			offsetp = offset +1;
			offsetm = offset -1;
			
			if (offset >0) {
				$('#gleft').attr('href', "javascript:get_mn_post('Naujienos', " + offsetm + ")");
			}
			else {
				$('#gleft').attr('href', "javascript:get_mn_post('Naujienos', " + offset + ")");
			}
			
			if (offset <3) {
				$('#gright').attr('href', "javascript:get_mn_post('Naujienos', " + offsetp + ")");
			}
			else {
				$('#gright').attr('href', "javascript:get_mn_post('Naujienos', " + offset + ")");
			}
		},
		"html"
	);
	
};


function cal_go_item(id) {
	$('.cal_panel .middle').fadeOut();
	$.post(
		template_directory + "/ajax.php",
		{func: "cal_go_item",
		 id: id},
		function(data){
			$(".cal_belt").html(data); 
			$('.cal_panel .middle').fadeIn('slow');
			setup_carousel('side_gallery');
		},
		"html"
	);
};


function setup_calendar() {

};


function setup_carousel(id) {
		var config=stepcarousel.configholder[id];
		config.$leftnavbutton.css({top: stepcarousel.getoffset(config.$gallery.get(0), "offsetTop")+20+'px'});
		config.$rightnavbutton.css({top: stepcarousel.getoffset(config.$gallery.get(0), "offsetTop")+20+'px'});
	try {

	}
	catch (err) {
	}
};

function run_calendar() {
	$('.left_arrow').click();
	var timeout = setTimeout('run_calendar()', 10000);
};


jQuery(
function() {

	$("#cat").append('<option selected="selected" value="21">Visi</option>');
	//$(".cat2").append('<option selected="selected" value="21">Visi</option>');
	
	coef = 7;
	// Calendar table bug:
	if ($.browser.mozilla) {
		$("#calendar_holder .calendar table").css({'margin': '1px 0 0 0'});
		$("#big_calendar_holder .big_calendar table").css({'margin': '1px 0 0 0'});
		coef = 8;
	}	

	if ($.browser.msie) {
	    if ($.browser.version.substr(0,1)=="7") {
			$(".commentlist .descr").css('margin-top', '-5px');
		}
	};

	var timeout =  setTimeout('run_calendar()', 10000);
	
	$('.left_arrow').click(function(){
		clearTimeout(timeout);
	});
	
	$('input[type="text"]').click(
		function() {
			this.value = '';
		}
	);
	
	$("#calendar_holder .prev_month").height($("#calendar_holder .calendar table").height()-coef);
	$("#calendar_holder .next_month").height($("#calendar_holder .calendar table").height()-coef);

	$("#big_calendar_holder .prev_month").height($("#big_calendar_holder .big_calendar table").height()-coef);
	$("#big_calendar_holder .next_month").height($("#big_calendar_holder .big_calendar table").height()-coef);
	
	$(".prev_month .middle p").css("padding-top", ($("#calendar_holder .calendar table").height()-24)/2);
	$(".next_month .middle p").css("padding-top", ($("#calendar_holder .calendar table").height()-24)/2);

	//$('#nyro a').nyroModal();
	
	$('.nyroModal').nyroModal({debug: false, bgColor: '#ffffff'});
	$('.gallery-icon a').attr('rel', 'gal');
	$('.gallery-icon a').nyroModal({debug: false, bgColor: '#ffffff'});
	
	
// Dropdown box: 	//////////////////////////////////
	 $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
     $("ul.topnav li span").click(function() { //When trigger is clicked...  
		
         //Following events are applied to the subnav itself (moving subnav up and down)  
         $(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click  
   
         $(this).parent().hover(function() {  
         }, function(){  
             $(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up  
         });  
   
         //Following events are applied to the trigger (Hover events for the trigger)  
         }).hover(function() {  
             $(this).addClass("subhover"); //On hover over, add class "subhover"  
         }, function(){  //On Hover Out  
             $(this).removeClass("subhover"); //On hover out, remove class "subhover"  
     });  		
				
				
	$("ul.subnav li a").click(function(event) {
		event.preventDefault();
		$("#q").attr("value", $(this).html());
		$("#rq").attr("value", $(this).attr('href'));
		$(this).parent().parent().slideUp('fast');
	});
///////////////////////////////////////////////////////	

}
);
