

//-- Slide down drop down menu	
var EffectSpeed = 150;
var blnSlideDownMenu = false;
var bSliding = false;

jQuery(document).ready(function() {	
	$("div.navigation-submenu ul li").mouseover(function() {
		blnSlideDownMenu = true;
		$(this).find("ul.submenu").slideDown(30, function() {
			$(this).parent().addClass("arrow");
			blnSlideDownMenu = false;
		});

		$(this).hover(function(){}, function(){
			if(blnSlideDownMenu === false) 
			{
				$(this).find("ul.submenu").slideUp('fast');
				$(this).removeClass("arrow");
			}
		});
	});
});

// TOOLTIP
jQuery(document).ready(function() {
	initToolTip("");
});

function initToolTip(strContainer){
	$(strContainer + ".tip").tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    extraClass: "", 
	    fixPNG: true,
	    top: 15,
	    left: 15
	});
	
	$(strContainer + ".tip-extra").tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    bodyHandler: function(){
	    	return $("div#" + $(this).attr("rel")).html();
	    },
	    extraClass: "", 
	    fixPNG: true,
	    top: 15,
	    left: 15
	});
}

jQuery(document).ready(function() {
	// FANCYBOX VOOR DE FOTO'S
	$("a.zoom").fancybox({
		'titlePosition'  : 'inside',
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic'
	});
	
	$(":input[type=button], :input[type=submit]").each(function(){
		$(this).removeAttr("disabled");
	});
	
	
	$(function() {
		$("img.hover").hover(function() {
			if($(this).attr("src").search(new RegExp("-hover", "i")) == -1) {
				$(this).attr("src", $(this).attr("src").split(".").join("-hover."));
			}
		}, function() {
			$(this).attr("src", $(this).attr("src").split("-hover.").join("."));
		});
	});
	
	//--Footer stretchen tot beneden
	//$("div.footer-copyright").height($(document).height() - $("div.wrapper").height() - $("div.footer-container").height() - 15);
	if($(document).height() <= $(window).height() && $(document).height() > $("section.container")[0].scrollHeight) {
		$("footer.footer-bottom").height($(document).height() - $("section.container").height() - $("footer.footer-bottom").height() + 66);
	}
});
			

//-- EXTERNAL LINKS

$(document).ready(function()
{
	$("a[href=#]").click(function()
	{
		return false;
	})

	$("a[rel=external]").click(function()
	{
		$(this).attr("target", "_blank");
	})
});

//-- Limit text
function limitText(limitField, limitCount, limitNum)
{
	if (limitField.value.length > limitNum)
	{
		limitField.value = limitField.value.substring(0, limitNum);
	}
	else
	{
		limitCount.value = limitNum - limitField.value.length;
	}
}


function DownloadFile(strFile, intItemno)
{
	if(intItemno != undefined)
	{
		window.location = "/" + strFile + "/" + intItemno + "/download";
	}
	else
	{
		window.location = "/" + strFile + "/download";
	}
}

function DownloadExtern(strFile, intItemno)
{
	window.open("/" + strFile + "/" + intItemno + "/extern", "_blank");
}

function slideToggleProductMenu(strId, strImageId)
{
	if ($("#" + strId).css("display") == "block")
	{
		$("#" + strId).slideUp();
		$("#" + strImageId).attr("src", strPath + "images/css/arrow-right.png");
	}
	else
	{
		$("#" + strId).slideDown();
		$("#" + strImageId).attr("src", strPath + "images/css/arrow-bottom.png");
	}
}

function writeFlash(p) 
{
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeWindowsMedia(p) 
{
	p.url = p.src;
	writeEmbed(
        '6BF52A52-394A-11D3-B153-00C04F79FAA6',
        'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
        'application/x-mplayer2',
        p
    );
}

function writeShockWave(p) 
{
    writeEmbed(
	    '166B1BCA-3F9C-11CF-8075-444553540000',
	    'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	    'application/x-director',
        p
    );
}

function writeQuickTime(p)
{
 	writeEmbed(
        '02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
        'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
        'video/quicktime',
        p
    );
}

function writeRealMedia(p) 
{
    writeEmbed(
        'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
        'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
        'audio/x-pn-realaudio-plugin',
        p
    );
}

function writeEmbed(cls, cb, mt, p) 
{
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

function writeYouTube(strMovieId, arrOptions)
{
	if (arrOptions == null) var arrOptions = new Array();
	if (arrOptions["containerID"] == null) arrOptions["containerID"] = "";
	if (arrOptions["width"] == null) arrOptions["width"] = 500;
	if (arrOptions["height"] == null) arrOptions["height"] = 300;
	if (arrOptions["swfversion"] == null) arrOptions["swfversion"] = "8";
	
	var strYouTubeUrl = "http://www.youtube.com/v/" + strMovieId;
	var strContainerId = arrOptions["containerID"];
	var intWidth = arrOptions["width"];
	var intHeight = arrOptions["height"];
	var strSWFVersion = arrOptions["swfversion"];
	var strExpressInstallSWF = null; //(Optional) Specifies the URL of your express install SWF. Not used in this example.
	var objFlashVars = null; //(Optional) Specifies your FlashVars in name:value pairs. Not used in this example. 
	var objEmbedVars = {}; //(Optional) The parameters for the embed object.
	var objAttr = {}; //(Optional) The attributes for the embed object.
	
	var oObj = swfobject.getObjectById(strContainerId);
	if (oObj)
	{
		var params = { allowScriptAccess: "always" };
    	var atts = { id: "testcontainer" };
    	
    	swfobject.embedSWF(strYouTubeUrl, strContainerId, intWidth, intHeight, strSWFVersion, strExpressInstallSWF, objFlashVars, objEmbedVars, objAttr);
	}
}

function submitForm(e, formID) 
{
	if (!e) var e = window.event;

	var keycode;

	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == "13") {
		document.getElementById(formID).submit();
	}
}

function submitCalculateRoute(e) 
{
	if (!e) var e = window.event;

	var keycode;

	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;

	if (keycode == "13") {
		calculateRoute();
	}
}

function checkValidEmail(strEmail) 
{
 	strEmailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/
 	return strEmailRe.test(strEmail);
}

function base64Encode(strData) 
{
    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
        ac = 0,
        enc = "",
        tmp_arr = [];

    if (!strData) {
        return strData;
    }

    strData = this.utf8_encode(strData + '');

    do { // pack three octets into four hexets
        o1 = strData.charCodeAt(i++);
        o2 = strData.charCodeAt(i++);
        o3 = strData.charCodeAt(i++);

        bits = o1 << 16 | o2 << 8 | o3;

        h1 = bits >> 18 & 0x3f;
        h2 = bits >> 12 & 0x3f;
        h3 = bits >> 6 & 0x3f;
        h4 = bits & 0x3f;

        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < strData.length);

    enc = tmp_arr.join('');

    switch (strData.length % 3) {
    case 1:
        enc = enc.slice(0, -2) + '==';
        break;
    case 2:
        enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}

function utf8_encode(argString) {
    if (argString === null || typeof argString === "undefined") {
        return "";
    }

    var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
    var utftext = "",
        start, end, stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.slice(start, end);
            }
            utftext += enc;
            start = end = n + 1;
        }
    }

    if (end > start) {
        utftext += string.slice(start, stringl);
    }

    return utftext;
}

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {var x = Math.round(num * Math.pow(10,dec));if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;}

function hoverProductCat(oObj, strColorHover, strColorOut, bHover) 
{
	if (bHover === true && strColorHover != "")
	{
		$(oObj).children(":first-child").css("color", "#" + strColorHover);
	}
	else
	{
		if (strColorOut != "")
		{
			$(oObj).children(":first-child").css("color", "#" + strColorOut);
		}
	}
}

function LoadItem(oObj, strModule) 
{
	var strAlias = $(oObj).val();
		
	if(strAlias != "") {
		strAlias = "/" + strAlias;
	}
		
	window.location = "/" + strLang + "/" + strModule + strAlias;
}

function calculate_date(date) {
	var date = date.replace(" ", "");
	
	if (date.indexOf('.') > 0) {
		/*date a, format dd.mn.(yyyy) ; (year is optional)*/
		var eu_date = date.split('.');
	} else {
		/*date a, format dd/mn/(yyyy) ; (year is optional)*/
		var eu_date = date.split('/');
	}
	
	/*year (optional)*/
	if (eu_date[2]) {
		var year = eu_date[2];
	} else {
		var year = 0;
	}
	
	/*month*/
	var month = eu_date[1];
	if (month.length == 1) {
		month = 0+month;
	}
	
	/*day*/
	var day = eu_date[0];
	if (day.length == 1) {
		day = 0+day;
	}
	
	return (year + month + day) * 1;
}

function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	
	if (event.toElement){
		current_mouse_target = event.toElement;
	}else if (event.relatedTarget){
		current_mouse_target = event.relatedTarget;
	}
	
	if (!is_child_of(element, current_mouse_target) && element != current_mouse_target){
		eval(JavaScript_code);
	}
}

function is_child_of(parent, child) {
		if (child != null){
			while (child.parentNode){
				if ((child = child.parentNode) == parent){
					return true;
				}
			}
		}
		
		return false;
	}
	
function showHideMiniBasket(bShow){
	if (bSliding === false){
		if (bShow === true){
			$("div.mini-cart-detail").slideDown('fast', function(){bSliding = false;});
		}else{
			$("div.mini-cart-detail").slideUp('fast', function(){bSliding = false;});
		}
	}
}

function changeProjectenSortOrder(oObj, strField){
	var strParams = "field=" + strField;
				
	$.post(strPath + "ajax-sort-projects.php", strParams, function(objResponse)
	{
		window.location.reload(true);
	}, "json");
}
