var nextNewsPage = '';
var currentNewsPage = '';
var zindex=28;
var flagform = false;

$(document).ready(function(){	
	
	
	$.ajaxSetup({
            cache: false
        });

	
	$("#moreNews").click(function(){            
		if(flagform) {
			$("#homeForm").css("z-index", 25);
                        $('#newsthanks').css("z-index", 26);
			$("#news").css("z-index", 27);
			$("#FormView").parent().removeClass("active");
			$("#news").show('slide', 1000, function(){$("#homeForm").css("display", "none");$('#newsthanks').remove();});
			flagform = false;
		}
		else {
                   var url = $(this).attr('href');
                    url +='.json';
                   $.getJSON(
                        url,
                        {},
                        function(item)
                        {
                            //item = $.parseJSON(data);
                            //console.log(item);
                            url = $('#moreNews').attr('href');
                            if (item.nextpage==-1)
                            {
                                item.nextpage = 0;
                            }
                            newurl = url.split('/'+ item.previous).join('/' + item.nextpage);
                            $('#moreNews').attr('href', newurl);
                            $('#newsthanks').css("z-index", 26);
                            $('#news').append(item.content);
                            $("#NewsPart_" + nextNewsPage).css('z-index', zindex);
                            zindex++;
                            $("#NewsPart_" + nextNewsPage).show('slide', 1000, function(data) {
                                $('#NewsPart_' + currentNewsPage).remove();
                                $('#newsthanks').remove();
                                currentNewsPage = item.previous;
                                 nextNewsPage = item.nextpage;          
                            });

                        }
                    );
                    //$("#NewsPart_2").show('slide', 1000);
		}
                return false;
	});									
	
	$("#FormView").click(function(){
            if (!flagform)
                {
		flagform = true;
		$(this).parent().addClass("active");
                $('#name').val('');
                $('#adres').val('');
                $('#zipcode').val('');
                $('#residence').val('');
                $('#email').val('');
                $('#name, #adres, #zipcode, #residence').removeClass('error');
		$("#homeForm").css("display", "block");
		$("#news").css("z-index", 25);
		$("#homeForm").css("z-index", 26);
		$("#homeForm").show('slide', 1000, function() {
                    $('#news').hide();
                });
                }
	});

        /**
	$(".lang a").click(function(){
                        obj = $(this)
                        url=$(this).attr('href');
                        url +='.json';
			if($(this).hasClass("en")) {
                            $.getJSON(url, {}, function(data) {

				obj.addClass("nl");
				obj.removeClass("en");
                                obj.attr('href', data.url)
                                $("#homeRightAreaEn").html(data.lawyer);
				$("#homeRightAreaInd").css("z-index", 25);
				$("#homeRightAreaEn").css("z-index", 26);
				$("#homeRightAreaEn").show('slide', 1000);
                                $('.left-nav a').each(function() {                                   
                                    url = $(this).attr('href');
                                    newurl=url.split('nl').join('en');
                                    $(this).attr('href', newurl);
                                });
                                $('.foot-nav a').each(function() {
                                    url = $(this).attr('href');
                                    newurl=url.split('nl').join('en');
                                    $(this).attr('href', newurl);
                                });
                             });
			}
			else {
                            $.getJSON(url, {}, function(data) {
                                obj.attr('href', data.url)
                                obj.addClass("en");
				obj.removeClass("nl");
				$("#homeRightAreaEn").css("z-index", 25);
                                $('#homeRightAreaInd').html(data.content);
				$("#homeRightAreaInd").css("z-index", 26);
				$("#homeRightAreaInd").show('slide', 1000);
                                $('.left-nav a').each(function() {
                                    url = $(this).attr('href');
                                    newurl=url.split('en').join('nl');
                                    $(this).attr('href', newurl);
                                });
                                $('.foot-nav a').each(function() {
                                    url = $(this).attr('href');
                                    newurl=url.split('en').join('nl');
                                    $(this).attr('href', newurl);
                                });
                                
                            });
				
			}
                        return false;
	});
	**/
	
	
	
	
});

function shownewscontent(obj)
{   
    url = $(obj).attr('href');
    url += '.json';    
    $.getJSON(url, {},
    function(item)
    {
        //alert(data);
        //item = $.getJSON(data);
        if (item.exists==1)
        {
            $('#newsWrapper').append(item.leftcolumn);

            $("#homeIndText .float-block").css("z-index", 25);
            $("#homeIndText").css("z-index", 25);
            var last = $("#newsWrapper").find('div:last').parent();
            var first = $("#newsWrapper").find('div:first');           
            first.css("z-index", 26);
            last.css("z-index", 27);
            last.show('slide', 1000, function () {
                $("#newsWrapper").find('div:first').remove();
            });
        }
    }
    );
    return false;
}

function newsback()
{    
   $("#newsWrapper").find('div:first').css("z-index", 25);
   $("#homeIndText .float-block").css("z-index", 26);
   $("#homeIndText").css("z-index", 26);
   $("#homeIndText .float-block").show('slide', 1000, function(data) {
       $("#newsWrapper").find('div:first').css('height', '0px').css('width', '0px').html('');
   });
}

function showadditionalcontent(obj)
{
    url = $(obj).attr('href');
    url +='.json';
    $.getJSON(url, {}, function(item) {
      if (item.exists == 1)
      {
          $("#newsWrapper .prev-page").css("visibility", "hidden");
          $("#homeRightAreaInd").css("z-index", 25);
          $("#newsBlock").css("z-index", 26);
          $("#newsBlockMore").html(item.text);
          $("#newsBlockMore").show('slide', 1000);
      }
    });
}

function newsbacktopage()
{
    $("#newsBlockMore").css("z-index", 25);
    $("#homeRightAreaInd").css("z-index", 26);
    $("#homeRightAreaInd").show('slide', 1000, function(){$("#newsBlockMore").css("display", "none");});
    $("#newsWrapper .prev-page").css("visibility", "visible");
}
