// browser sniffer
var Browser = function(){
  this.uA = navigator.userAgent.toLowerCase();
  this.aN = navigator.appName.toLowerCase();
  this.iE = this.aN.indexOf('microsoft') != -1 ? 1 : 0;
  this.mac =  this.uA.indexOf('mac') != -1 ? 1 : 0;
  this.win = this.uA.indexOf('windows') != -1 ? 1 : 0;
  this.safari =  this.uA.indexOf('webkit') != -1 ? 1 : 0;
  this.opera =  this.uA.indexOf('opera') != -1 ? 1 : 0;   
  this.operaMini =  this.uA.indexOf('mini') != -1 ? 1 : 0;  
  this.mozilla = this.aN.indexOf('netscape') != -1 && !this.safari ? 1 : 0;
  this.winMozilla = this.mozilla && this.win ? 1 : 0;
  this.winIE = this.iE && this.win && !this.opera ? 1 : 0;
  this.winIE6Down = this.winIE && parseInt(this.uA.split('msie ')[1].substring(0,1)) <= 6 ? 1: 0;
  this.macIE = this.iE && this.mac ? 1 : 0;
};
var browser = new Browser();
	

// addStyle
var addStyle = function(selector,properties){
  if (document.styleSheets) {
    var s = document.getElementsByTagName('STYLE');
    if (s.length == 0){
      var sheet = document.createElement('style');
      sheet.setAttribute('type','text/css');
      document.getElementsByTagName('HEAD')[0].appendChild(sheet);}
    if (browser.winIE){
      var lastSheet = document.styleSheets[document.styleSheets.length - 1];
      lastSheet.addRule(selector, properties);}
    else {var lastSheet = s[0];
      lastSheet.appendChild(document.createTextNode(selector + ' { ' + properties + ' }'));}
  	}
};
addStyle('.drempel','display:none;');
addStyle('.noscript','display: block !important;');


//incl. .js
var jsPath = "/Content/Javascript/";
document.write('<scr'+'ipt type="text/javascript" src="' + jsPath + 'swfobject.js"><\/scr'+'ipt>');
document.write('<scr'+'ipt type="text/javascript" src="' + jsPath + 'jquery.prettyPhoto.js"><\/scr'+'ipt>')
if (browser.winIE6Down){
	document.write('<scr'+'ipt type="text/javascript" src="' + jsPath + 'jquery.ifixpng.js"><\/scr'+'ipt>');
};

function isExternalUrl(url) {
    if(url.match("http://") != null) {
        if(url.match("meermetminder.nl") != null)
            return false;
        else
            return true;
    }
    if(url.match("www.") != null) {
        if(url.match("meermetminder.nl") != null)
            return false;
        else
            return true;
    }
    return false;
}

function externalLinkeMethod($elm, url) {
    if(url == null)
        url = $elm.attr("href");
    
    if(isExternalUrl(url)) {
        $elm.click(function() {
            // notice google!
            pageTracker._trackPageview('/out/'+url);
        });
    }
    
    if ($elm.attr("target") == ""){
        $elm.attr("target", "_blank");
    }
}

$(document).ready(function(){
// a href
    $.each($("a[href^='http://']"), function() {
        externalLinkeMethod($(this));
    });
// a href    
    $.each($("a[href^='www.']"), function() {
        var url = "http://" + $(this).attr("href");
        externalLinkeMethod($(this), url);
    });
// * rel
    $.each($("*[rel^='http://']"), function() {
        var url = $(this).attr("rel");
        if(isExternalUrl(url)) {
            $(this).click(function() {
                pageTracker._trackPageview('/out/'+url);
            });
        }
    });
// * rel
    $.each($("*[rel^='www.']"), function() {
        var url = "http://" + $(this).attr("rel");
        if(isExternalUrl(url)) {
            $(this).click(function() {
                pageTracker._trackPageview('/out/'+url);
            });
        }
    });
    
    $( function(){
        $("table").attr("border", "0");
        $("table tr:even").addClass("even");
        $("table tr:odd").addClass("odd");
    });
      
      
    //Apply CSS class to all A links that end in .pdf
    $("a[href$='.pdf']").addClass("pdf_icon");
    
    //Apply CSS class to all A links that end in .doc
    $("a[href$='.zip']").addClass("zip_icon");        
        
    $("div.banner").click(function() {
        var url = $(this).attr("rel");

        if(url != null) {
            document.location.href = url;
        }
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});
});

//DomLoad by Dean Edwards edited by Robert Cherny and Matthias Miller for https use.
var DomLoaded ={
	onload: [], loaded: function(){
	if (arguments.callee.done) return; arguments.callee.done = true;
	for (i = 0;i < DomLoaded.onload.length;i++) DomLoaded.onload[i](); }, load: function(fireThis) { this.onload.push(fireThis);
	if (document.addEventListener) { document.addEventListener("DOMContentLoaded", DomLoaded.loaded, null); };
	if (/KHTML|WebKit/i.test(navigator.userAgent)){ var _timer = setInterval(function(){ if (/loaded|complete/.test(document.readyState)){ clearInterval(_timer); delete _timer; DomLoaded.loaded();}}, 10);};
	/*@cc_on @*/
	/*@if (@_win32)
	var proto = "src='javascript:void(0)'"; if (location.protocol == "https:") proto = "src=//0";
	document.write("<scr"+"ipt id=__ie_onload defer " + proto + "><\/scr"+"ipt>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() { if (this.readyState == "complete") { DomLoaded.loaded(); } };
	/*@end @*/
   window.onload = DomLoaded.loaded; }
};

//DomLoaded.load(init);
DomLoaded.load(function() {
	//start onload events
	if (browser.winIE6Down){
		$('img[src$=.png]').ifixpng();
		try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {};
	};
	if (browser.safari) { $('input[type=file]').css({ backgroundColor: "transparent", border: "none"}); };
	
	//end onload events
	
});