﻿/***
 * TECHNISCHE REALISATIE:
 * VLC Projects B.V.
 * http://www.vlc.nl/
 ***/

//prevent flicker
preventflicker = function(){
    if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6) {
        try {
            document.execCommand('BackgroundImageCache', false, true);
        } catch(e) {}
    }
}

//collapsible site menu
sitemenu = function(){
    var _submenuLinks;
    
    function findSubmenuLinks(path) {
        return $(path);
    }
    
    function getSubmenu(anchor) {
        return anchor.next('ul');
    }
    
    function collapse(submenu) {
	if(submenu.is(":visible") == true) {
	    submenu.fadeOut(500);
	}
    }
    
    function expand(submenu) {
	if(submenu.is(":visible") == false) {
	    submenu.show(150);
	}
    }
    
    function bindSubmenuEvents(submenulinks) {
        submenulinks.each(function(){
            var submenu;
            submenu = getSubmenu($(this));
            
            submenu.parent().hover(       	     		//hide when mouseout
                    function(){expand(submenu)},
                    function(){collapse(submenu)}
                );
        });
    }
    
    return {
        init : function(){
            _submenuLinks = findSubmenuLinks("dd#site-menu>ul>li>a");
            bindSubmenuEvents(_submenuLinks);
        }
    };
}();

//round image corners in mediacollection
roundimage = function() {
	
    function getImages() {
    	return images = $(".mediacollection img");
    }
    
    function roundImages() {
        var images;
        
        images = getImages();
        images.each(function(){
            $(this).wrap("<div class='roundimage-wrapper' style='width:" + this.width + "px; height:" + this.height + "px'></div>");
            
            //by default round corners on left side
            $(this).after("<div class='roundimage-tl'></div>")
                   .after("<div class='roundimage-bl'></div>");
            
            //when image not in sidebar round the corners on the right side
            if( $(this).parents("div.sidebar").length != 1 ){
                $(this).after("<div class='roundimage-tr'></div>")
                       .after("<div class='roundimage-br'></div>");
            }
        });
    }
	
	return {
		init : function(){
			roundImages();
		}
	};
}();

$(document).ready(function(){
    preventflicker();
    sitemenu.init();
    roundimage.init();
});
