$(function(){
	
	if ($.browser.msie && $.browser.version < 7)
		$('img[src$=.png]').pngfix();

	$('img[hover],input[hover]').imghover();
		
	// activate paging for projectlist
	if ( $('ul.projectList').length > 0 ) {
        $('ul.projectList').paging({
            itemsPerPage: 6,
			elementType: 'li',
            prevText: '<span>&lt;</span>',
            nextText: '<span>&gt</span>',
			firstText: '<span>&lt;&lt;</span>',
            lastText: '<span>&gt;&gt</span>',
            selectedClass: 'selected',
            navClass: 'customnav',
            addNav: 'after',
            showPageNumbers: 'false'
        }).bind('pagingBeforePageChange',function(){
            }).bind('pagingAfterPageChange',function(){
            });
    };
	
	
	// show/hide search-pane
	$("a#toggleExtendedSearch").click(function () {
        if ($("div#extendedSearch").is(":hidden")) {
			$("a#toggleExtendedSearch").text("sluit", $(this).addClass('minus') );
			$("div#topbar").animate({"height": "120px"}, {duration: "slow"});
            $("div#extendedSearch").slideDown("slow");
		    return false;
        } else {
            $("div#extendedSearch").slideUp("slow", function (){
				$("a#toggleExtendedSearch").text("Uitgebreid zoeken");
				$("a#toggleExtendedSearch").removeClass('minus');
				$("div#topbar").animate({"height": "20px"}, {duration: "slow"});
			});			
		    return false;
        }
    });
	
	$('input.reset-default').focus(function() {
        if(this.value == this.defaultValue) {
	        $(this).removeClass('reset-default');
	        this.value = '';
        }
    }).blur(function() {
        if($(this).attr('value').replace(/ +/, '') == '') {
	        $(this).addClass('reset-default');
            this.value = this.defaultValue;
        }
    }).parents('form').submit(function() {
        $('input.reset-default', this).attr('value', '');
    });
	
	// init subnavigation
	$("ul.sf-menu").superfish();
	
	
	$('div#rightCol hr').replaceWith('<div class="ruler"></div>');
	
	
	/* Fix wmode2transparent */
	// FireFox
	$("embed").attr("wmode", "opaque");

	// IE
    var embedTag;
    $("embed").each(function(i) {
        embedTag = $(this).attr("outerHTML");
        if ((embedTag != null) && (embedTag.length > 0)) {
            embedTag = embedTag.replace(/embed /gi, "embed wmode=\"opaque\" ");
            $(this).attr("outerHTML", embedTag);
        }
        // This "else" was added
        else {
            $(this).wrap("<span></span>");
        }
    });

		 
});

function paging(){
    if ( $('.pageingitems').length > 0 ) {
        $('.pageingitems').paging({
            itemsPerPage: 5,
            elementType: 'li',
            prevText: '<span>&lt;</span>',
            nextText: '<span>&gt</span>',
			firstText: '<span>&lt;&lt;</span>',
            lastText: '<span>&gt;&gt</span>',
            selectedClass: 'selected',
            navClass: 'customnav',
            addNav: 'after',
            showPageNumbers: 'false'
        }).bind('pagingBeforePageChange',function(){
            }).bind('pagingAfterPageChange',function(){
            });
    };
}

;(function($){
	$.fn.pngfix = function () {	
		if ($.browser.msie && $.browser.version < 7) {
			return this.each (function () {
				$(this).css({
					filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"')"
				});
				this.src = 'images/blank.gif';
			});
		} else {
			return this;
		}
	};

	$.prefetch = function() {
		for(var i = 0; i<arguments.length; i++)  {
			$("<img>").attr("src", arguments[i]);
		}
	}

	$.fn.imghover = function () {
		return this.each (function () {
			$(this).data('__img__original', this.src);
			$.prefetch($(this).attr('hover'));
		}).hover(function(){
			this.src = $(this).attr('hover');
		},function(){
			this.src = $(this).data('__img__original');
		});
	};
})(jQuery);


$(document).ready(function (){
    var baseHref = $('base').attr('href');

    paging();
	
    $('div#newsItemOverview div.engflag').click(function (){
        var myId      = $(this).attr('id');
        //var me        = $(this);
        var myFlagImg = $(this).find('img');


        $.ajax({
            url: baseHref + 'nieuws/loadsingleitem',
            data: 'id=' + myId,
            type: 'post',
            dataType: 'json',
            beforeSend: function ()
            {
               myFlagImg.attr('src', baseHref + 'images/loading.gif');
            },
            success: function (json){
                myFlagImg.attr('src', baseHref + 'images/icons/english-flag.gif');
                $("#news_item_h_" + json.news_id).find('a').html(json.title);
                $("#news_item_h_" + json.news_id).find('a').attr('href', json.url);
                $("#news_item_a_" + json.news_id).attr('href', json.url);
                $("#news_item_p_" + json.news_id).html(json.summary + '<p><a href="' + json.url + '">read more</a></p>');
            }
        });

    });


    if ($("#formNewsOverview").length > 0)
    {
    }
    /*
    if ($("#formNewsOverview").length > 0)
    {
        $("#formNewsOverview").ajaxForm({
            url: baseHref + 'nieuws/reloadbyfilter/',
            type: 'post',
            dataType: 'html',
            beforeSend: function () {
                $("#formNewsOverview").find('input[type=checkbox]').attr('disabled', 'disabled');
                $("#newsOverviewLoader").show();
                $("#newsItemOverview").find(".customnav").hide();
                $('#newsBlockList').html('');
            },
            success: function (html) {
                $("#formNewsOverview").find('input[type=checkbox]').removeAttr('disabled');
                $("#newsOverviewLoader").hide();
                $("#newsItemOverview").find(".customnav").show();
                $('#newsBlockList').html(html);
                paging();
            }
        });

        $('ul.filters input').click(function (){
            $("#formNewsOverview").submit();
        });
    }
    */
});