var sUrl = document.location.href;
var sUrlSplit = document.location.href.split('http://');
sUrl = sUrlSplit[1];
sUrl = sUrl.split("/");
sUrl = "http://"+sUrl[0];
var iBusy=0;
var iType="";

$(document).ready(function() {
	
	$('#slider').innerfade({
			speed: 'slow',
			timeout: 15000,
			type: 'sequence',
			containerheight: '263px'
	});

	$("a[rel=example_group]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition' 	: 'over',
		'showNavArrows'		: true,
		'overlayOpacity'	: 0.6, 
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
	});	

});

function searchArticles(sValue,m_id,c_name)
{
	if (iBusy==0)
	{
		theForm = "search="+sValue+"&m_id="+m_id+"&content_name="+c_name;
       		make_request(sUrl+'/assets/ajax/aArticles.php', 'returnNewsPage', 'POST', theForm); 
	}
}

function gotoNewsPage(iPage,m_id,c_name)
{
	if (iBusy==0)
	{
		document.getElementById('article_items').innerHTML = '<img class="normal" align="absmiddle" src="'+sUrl+'/assets/images/icons/loading_orange.gif" alt="De berichten worden geladen" /> De berichten worden geladen.';
		theForm = "page="+iPage+"&m_id="+m_id+"&content_name="+c_name;
        	make_request(sUrl+'/assets/ajax/aArticles.php', 'returnNewsPage', 'POST', theForm); 
		iBusy=1;
	}
}

function returnNewsPage(result)
{
	//alert(result);

	var aResult = result.split('|%|%|');
	document.getElementById('article_items').innerHTML = aResult[0];
	document.getElementById('pag_nav').innerHTML = aResult[1];

	iBusy=0;

}

 function create_http_object() 
    { 
        var ActiveXTypes = [ 
            "Microsoft.XMLHTTP", 
            "MSXML2.XMLHTTP.5.0", 
            "MSXML2.XMLHTTP.4.0", 
            "MSXML2.XMLHTTP.3.0", 
            "MSXML2.XMLHTTP" 
        ]; 

        for( var i = 0; i < ActiveXTypes.length; i++ ) 
        { 
            try 
            { 
                return new ActiveXObject( ActiveXTypes[i] ); 
            } 
            catch( e ) 
            { } 
        } 

        try 
        { 
            return new XMLHttpRequest(); 
        } 
        catch( e ) 
        { } 

        return false; 
    } 

    function make_request(url, callback_function, http_method, post_values, return_xml) 
    { 
        http = create_http_object(); 

        if(!http) 
        { 
            alert('Je browser ondersteunt deze feature niet.'); 
            return false; 
        } 


        http.onreadystatechange = function() 
        { 
            if(http.readyState == 4) 
            { 
                if(http.status == 200) 
                { 
                    if(callback_function) 
                    { 
                        if(return_xml) 
                        { 
                            eval(callback_function + '(http.responseXML)'); 
                        } 
                        else 
                        { 
                            eval(callback_function + '(http.responseText)'); 
                        } 
                    } 
                } 
                else 
                { 
                    alert('Error! (' + http.status + ')'); 
                } 
            } 
        } 

        if(!post_values) 
        { 
            post_values = null; 
        } 
        if(!http_method) 
        { 
            http_method = "GET"; 
        } 

        http.open(http_method, url, true); 

        if(http_method == "POST") 
        { 
            http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
        } 

        http.send(post_values); 
    } 
