/* slidemeue PlugIn START */

/*********************
/**
 * @global => ACTIONS for PC & EWT after EMO
 */
(function($){
    $.triumpgBgImg = (function(){
        var viewport, imgSize, imgDim, staticImg, imgNum;
        function calcViewport(){
            viewport = {
                height: $(window).height(),
                width: $(window).width()
            };
        }
        
        function calcImgSize(img){
            if (img[0]) {
                imgDim = {
                    height: img.height(),
                    width: img.width()
                };
            }
        }
        
        function adjustBgImg(){
            img = staticImg;
            
            calcImgSize(img);/* + mkalmes (20110622: js error fixed by flash pages after 1. reload)*/
            
            calcViewport();
            
            var windowRatio = viewport.width / viewport.height, imgRatio = imgDim.width / imgDim.height;
            if (windowRatio < imgRatio) {
                img.css({
                    width: 'auto',
                    height: viewport.height + 'px'
                });
            }
            else {
                img.css({
                    width: '100%',
                    height: 'auto'
                });
            }
            
        }
        function showNext(){
        
            staticImg = $('#bg-img img:last');
            calcImgSize(staticImg);
            adjustBgImg(staticImg);
            $('#overlay').animate({
                opacity: 0.9,
                backgroundColor: '#ffffff'
            }, {
                duration: 400,
                complete: function(){
                    staticImg.css({
                        opacity: 1
                    });
                    $('#bg-img img:first').remove();
                }
            }).animate({
                opacity: 0.5,
                backgroundColor: '#000000'
            }, {
                duration: 400
            });
        }
        function loadNext(path){
            var img = new Image();
            img.src = path;
            $(img).css({
                opacity: 0
            }).appendTo($('#bg-img')[0]);
            if (img.complete) {
                showNext();
            }
            else {
                $(img).load(showNext);
            }
            
        }
        
        return {
            init: function(){
                staticImg = $('#bg-img img:first');
                if (staticImg && staticImg[0]) {
                    if (staticImg[0].complete) {
                        calcImgSize(staticImg);
                        adjustBgImg(staticImg);
                        $(window).bind('resize', adjustBgImg);
                    }
                    else {
                        staticImg.bind('load', function(){
                            calcImgSize(staticImg);
                            adjustBgImg(staticImg);
                        });
                        $(window).bind('resize', adjustBgImg);
                    }
                }
                
            },
            loadNext: loadNext
        
        };
    })();
    (function($){
        $.imgPreLoad = (function(){
            var srcList = [], ready = false, started = false;
            function loadImg(){
                if (srcList.length) {
                    started = true;
                    var src = srcList.shift(), img = new Image();
                    img.src = src;
                    if (img.complete) {
                        loadImg();
                    }
                    else {
                        $(img).load(loadImg);
                    }
                }
                else {
                    started = false;
                }
            }
            return {
                add: function(src){
                    srcList.push(src);
                    if (ready && !started) {
                        loadImg();
                    }
                },
                ready: function(){
                    ready = true;
                    loadImg();
                }
            };
        })();
        $(window).bind('load', $.imgPreLoad.ready);
    })(jQuery);
    
    
    function callGlobal(){
        $.triumpgBgImg.init();
    }
    $(callGlobal);
})(jQuery);

function setBacklinkCookie(url, flash, text){
	$.cookie('triumph_bcklnk', window.location, { path: '/' });
	if (typeof(text) != 'undefined')
		$.cookie('triumph_bcklnk_text', text, { path: '/' });
}

$(document).ready(function() {
	
	//delete dadLinks from MainNavi
	if (cmsflash == false){
		var $mainmenu = $("#slidemenu ul li:not(#slidemenu ul li ul li)");
		$mainmenu.each(function (index, domEle) {
			if ($('ul',domEle).length > 0) {
				$(this).children("a:eq(0)").attr('href','#');
			}
		})
		$('.navPO a').attr('href','#');
	}
  
	//@anizold
	//get cookie and activate backlink on pc if cookie != null
	if ($('#catalogue_back').length > 0)
		if ($.cookie('triumph_bcklnk') != 'null' && $.cookie('triumph_bcklnk') != null) {
			$('#catalogue_back a').attr('href', $.cookie('triumph_bcklnk'));
			if ($.cookie('triumph_bcklnk_text') != 'null' && $.cookie('triumph_bcklnk_text') != null)
				$('#catalogue_back a').html($.cookie('triumph_bcklnk_text'));
			$('#catalogue_back').show();
		} else
			$('#catalogue_back').remove();
  
	//search for name="backlink" to set cookie with url as value by click on anchor
	$('a[name=backlink]').each(function() {
		$(this).bind('click', function() {
			$.cookie('triumph_bcklnk', window.location, { path: '/' });
		});
	});
  
	//delete cookie by clicking backlink
	if ($('#catalogue_back').length > 0)
		$('#catalogue_back a').bind('click', function() {
			$.cookie('triumph_bcklnk', 'null', { path: '/' });
			$.cookie('triumph_bcklnk_text', 'null', { path: '/' });
		});
	
});


function newpopup(site,w,h) {
    x = screen.availWidth / 2 - w / 2;
    y = screen.availHeight / 2 - h / 2;
    window.open (site,'','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',screenX=' + x + ',screenY=' + y + ',scrollbars=no,resizable=yes');
}
