function getUrlParameters()
{
    var parameters = new Array();
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        parameters.push(hash[0]);
        parameters[hash[0]] = hash[1];
    }
    return parameters;
}

var urlParameters = getUrlParameters();

var SvNl = {}

$(document).ready(function () {
    //gatc();
    dynamic_forms();
    rewritePrintHref();
    //SvNl.ajax.init();		

    $("#topcomments").kmSlider();
    $("#lnkFacebook").attr("href", "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(location.href) + "&t=" + encodeURIComponent(document.title));
    
    // Inforuta
    // By suppling no content attribute, the library uses each elements title attribute by default
    $('.relatedContent a[href][title]').qtip({
       content: {
          text: false // Use each elements title attribute
       },
   style: { 
       width: 300,
       padding: 5,
       background: '#fff6d9',
       color: 'black',
       border: {
          width: 4,
          radius: 5,
          color: '#fe9900'
       },
       tip: 'topLeft',
       name: 'dark' // Inherit the rest of the attributes from the preset dark style
    }
    });
    
    // NOTE: You can even omit all options and simply replace the regular title tooltips like so:
    // $('#content a[href]').qtip();
    
    
});

SvNl.ajax = {

    init: function () {

        $.ajaxSetup({
            cache: false
        });

        var rssBoxes = $('.rssBox');

        if (rssBoxes.length > 0) {
            rssBoxes.each(function () {
                var ids = $(this).attr('id');
                if (ids != null && ids != "") {
                    var articleString = ids.match('article:(\\d*)');
                    var articleId = articleString[1].match('\\d*');
                    var url = '?service=Ajax&component=rss&articleId=' + articleId;
                    $(this).load(url);
                }
            });
        }

        var rssWideUtf8Boxes = $('.rssWideUtf8Boxes');
        if (rssWideUtf8Boxes !== null && rssWideUtf8Boxes.length > 0) {
            rssWideUtf8Boxes.each(function () {
                var ids = $(this).attr('id');
                if (ids != null && ids != "") {
                    var articleString = ids.match('article:(\\d*)');
                    var articleId = articleString[1].match('\\d*');
                    var url = '?service=UTF8&component=rssUtf8Wide&articleId=' + articleId;
                    $(this).load(url);
                }
            });
        }
    }
};

/* kmSlider */
(function ($) {
    $.fn.kmSlider = function (options) {
        this.each(function () {
            var obj = $(this);
            var s = $("li", obj).length;
            var ts = s - 1;
            var t = 0;
            
            $("li", obj).hide();
            $("li:eq(0)", obj).show();
            
            $("#btnNextComment").click(function () {
                goto("next", true);
            });
            $("#btnPreviousComment").click(function () {
                goto("prev", true);
            });

            $(obj.parent()).mouseout(function () {
                timeout = setTimeout(function () {
	                goto("next", false);
	            }, 10000);
	        });

            $(obj.parent()).mouseover(function () {
                clearTimeout(timeout);
            });
            
            function goto(dir, clicked) {
                var ot = t;
                switch (dir) {
                    case "next":
                        t = (ot >= ts) ? 0 : t + 1;
                        break;
                    case "prev":
                        t = (t <= 0) ? ts : t - 1;
                        break;
                    default:
                        break;
                };
                
                $(obj).find('li:eq(' + ot + ')').fadeOut('slow', function () {
                    $(obj).find('li:eq(' + t + ')').fadeIn("slow");
                });

                if(clicked) {
                    clearTimeout(timeout);
                } else {
                    timeout = setTimeout(function () {
                        goto("next", false);
                    }, 10000);
                };

            };
            // init
            var timeout;
        });

    };

})(jQuery);

$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


