$(document).ready(function(){
//flash-detection
      if( cmsflash != true){
        var flashvars = {
          rootpath: root_path
        };
        var params = {
          /*base : "./front/",*/
          scale: "noscale",
          allowFullScreen: "true",
          wmode: "transparent"
        };
        var minFlashVersion = 10;
	    var flashVersion = swfobject.getFlashPlayerVersion();
	    if (flashVersion.major >= minFlashVersion ) {
	    	$('#flashContent').before($('#toolbar-underlay'));
        	swfobject.embedSWF("../../global/Main.swf", "flashContent", "100%", "100%", "10.0.0", "../../global/scripts/emo/expressInstall.swf", flashvars, params, {id: 'flashContent'});
	        swffit.fit("flashContent",940,600);
        } else {
        	$('#flashContent').css('visibility', 'visible');
        }
      }
});


/**
 * @author alexander.farkas
 */

(function($){
    
    function callOnReady(){

    }
    $(callOnReady);

})(jQuery);


(function($){
    (function($){
        $.widget('ui.imageGallery', {
            init: function(){
                var that = this, o = this.options;
                this.links = $(o.link, this.element[0]);
                this.imageStage = $(o.imageStage, this.element[0]);
                this.imageStage.attr('tabIndex', '-1');
                if ($.imgPreLoad) {
                    this.links.each(function(){
                        $.imgPreLoad.add($(this).attr('href'));
                    });
                }
                function switchPic(e){
                  $(this).animate({
                        opacity: 0
                        }, {
                          duration: 300,
                          complete: function(){
                            var allSlidesContainer = $(this).closest("ul");
                            allSlidesContainer.find('li').show();
                            $(this).animate({
                                  opacity: 100
                                  }, {
                                  duration: 300});
                            $(this).parent().parent().hide();
                          }
                        });
                    that.switchImgStage.call(that, this, e);
                    setTimeout(function(){
                        that.imageStage.focus();
                    }, 200);
                    return false;
                }
                this.links.bind('click.imageGallery', switchPic).attr('role', 'button');
                
            },
            switchImgStage: function(elm, e){

                var jElm = $(elm), src = jElm.attr('href');
                this.links.removeClass('active');
                jElm.addClass('active');
                if (!this.options.switchImgFn) {
                    $('img', this.imageStage).attr('src', src);
                }
                else {
                    this.options.switchImgFn.call(this, src, jElm);
                }
            }
        });
        $.ui.imageGallery.defaults = {
            link: 'a',
            imageStage: 'div.photo',
            switchImgFn: false
        };
    })(jQuery);
    var zoomGallery = (function(){
        var img, jImg, zoomContainer, gallery, galleryDim, nowDim, dimArray, poses, zoomImage;
        
        function constrainToGallery(left, top, width, height){
            width = width || parseFloat(img.style.width, 10);
            height = height || parseFloat(img.style.height, 10);
            
            var maxMin = $.objScale.constrainMaxMinPositionForContainer(
                {
                    width: width, 
                    height: height
                }, galleryDim, 
                {
                    left: left,
                    top: top
                });
            return [maxMin.left, maxMin.top];
        }
        
        function dragImg(e){
            
            var x = poses.x - e.clientX, 
                y = poses.y - e.clientY, 
                left = poses.left - x, 
                top = poses.top - y;
            var nPos = constrainToGallery(left, top);
            nPos[0] = nPos[0] || 0;
            nPos[1] = nPos[1] || 0;
            img.style.left = nPos[0] + 'px';
            img.style.top = nPos[1] + 'px';
            poses = {
                x: e.clientX || 0,
                y: e.clientY || 0,
                top: nPos[1],
                left: nPos[0]
            };
        }
        function scale(){
            var dir = (this.className == 'zoom-in') ? 1 : -1;
           
            if (dimArray[nowDim + dir]) {
                nowDim += dir;
                var pos = {
                        top: parseFloat(img.style.top) + ((parseFloat(img.style.height) - dimArray[nowDim].height) / 2),
                        left: parseFloat(img.style.left) + ((parseFloat(img.style.width) - dimArray[nowDim].width) / 2)
                    },
                    cPos = constrainToGallery(pos.left, pos.top, dimArray[nowDim].width, dimArray[nowDim].height);
                
                pos.left = cPos[0];
                pos.top = cPos[1];
                var css = $.extend({}, dimArray[nowDim], pos);
                jImg.animate(css, {duration: 200});
            }
            return false;
        }
        function mouseDown(e){
            poses = {
                x: e.clientX,
                y: e.clientY,
                top: parseFloat(img.style.top, 10),
                left: parseFloat(img.style.left, 10)
            };
        }
        
        function prepareNewImg(){
            var imgDim = $.objScale.scaleSidesIn(this, galleryDim),
                difDim = {
                    width: galleryDim.width - imgDim.width,
                    height: galleryDim.height - imgDim.height
                };
            if(difDim.width < 5 && difDim.width > 0){
                imgDim.height = $.objScale.scaleWidthTo(imgDim, galleryDim.width);
                imgDim.width = galleryDim.width;
            } else if(difDim.height < 5 && difDim.height > 0){
                imgDim.width = $.objScale.scaleHeightTo(imgDim, galleryDim.height);
                imgDim.height = galleryDim.height;
                
            }
            var maxDim = {width: this.width, height: this.height};
            
            nowDim = 0;
            var stepWidth = (Math.abs(imgDim.width - maxDim.width)) / 3, stepHeight = (Math.abs(imgDim.height - maxDim.height)) / 3;
            dimArray = $.extend({}, imgDim);
            delete dimArray.margin;
            dimArray = [dimArray];
            for (var i = 0; i < 2; i++) {
                dimArray.push({
                    width: imgDim.width + stepWidth,
                    height: imgDim.height + stepHeight
                });
                
                stepWidth += stepWidth;
                stepHeight += stepHeight;
            }
            dimArray.push($.extend({}, maxDim));
            var css = {
                position: 'absolute',
                width: imgDim.width,
                height: imgDim.height,
                top: imgDim.margin[0],
                left: imgDim.margin[1],
                opacity: 0
            };
            jImg.css(css)
                .prependTo(zoomContainer[0])
                .animate({
                    opacity: 1
                },
                {
                    duration: 200
                })
                .bind('mousedown', mouseDown);
            
            
            var mouseDrag = new MouseDrag();
            mouseDrag.mouseInit();
            
        }
        function MouseDrag(){
            this.element = jImg;
            this.options = $.ui.mouse.defaults;
        }
        $.extend(MouseDrag.prototype, $.ui.mouse, {
            mouseDrag: dragImg
        });
        function switchImage(src, jElm){
            $('img:first', zoomContainer[0]).animate({
                opacity: 0
            }, {
                duration: 300,
                complete: function(){
                    $(this).remove();
                }
            });
            img = new Image();
            jImg = $(img);
            jImg.load(prepareNewImg);
            img.src = src;
        }
        function init(){
            gallery = $('#ser_right');
            zoomImage = $('#zoom-image');
            if (gallery[0] && zoomImage.length == 0) {
                var imgSrc = $('#ser_slider a').attr('href');
                img = new Image();
                zoomContainer = $('<div id="zoom-image"><div class="zoom-control"><a href="#" class="zoom-in">zoom in</a><a href="#" class="zoom-out">zoom out</a></div></div>');
                zoomContainer.appendTo('#ser_middle_bg');
                galleryDim = {
                    width: $('#zoom-image').innerWidth(),
                    height: $('#zoom-image').innerHeight()
                };
                $('#ser_right').imageGallery({
                    imageStage: '#zoom-image',
                    link: '#ser_slider a',
                    switchImgFn: switchImage
                });
                jImg = $(img);
                jImg.load(prepareNewImg);
                img.src = imgSrc;
                $('a', zoomContainer[0]).click(scale);
            }
        }
        return {
            init: init,
            element: jImg,
            dragImg: dragImg
        };
    })();
    
    function callSlider(){
      if($("#ser_slider").length == 1){
        $("#ser_slider li[id='"+stdProduct+"']").hide();
        $("#ser_slider").easySlider({
          prevText:'UP',
          nextText:'DOWN',
          orientation:'vertical',
          showElements:'5',
          hiddenElements:'1',
          contHeight: '430',
          nextButt:'ser_right_next',
          prevButt:'ser_right_prev'
        });
      }
    }

    function callGallSlide(){
      if($("#dbgallery_slider").length == 1){
        $('#dbgallery_slider').easySliderGall({
          prevText:'UP',
          nextText:'DOWN',
          orientation:'horizontal',
          showElements:'1',
          prevButt:'dbgallery_prev',
          nextButt:'dbgallery_next',
          contWidth:'441'
        });
      }
    }

    function callTeaser(){
      if($('.teasing').length > 0){
        $('.teasing').mouseover(function(){
          $('.teaseOverlayText', this).show('slow')
        }).mouseout(function(){
          $('.teaseOverlayText', this).hide('fast');
        });
      }
    }

    function callGalleryReady(){
        zoomGallery.init();
        callSlider();
        callTeaser();
        callGallSlide();
    }
    $(callGalleryReady);
})(jQuery);

$(document).ready(function(){
  $("#seg_slider").easySlider({
    prevText:'UP',
    nextText:'DOWN',
    orientation:'vertical',
    showElements:'2',
    contHeight: '332',
    nextButt:'ser_right_next',
    prevButt:'ser_right_prev'
  });
});

$(document).ready(function(){
//DASHBOARD: Page Flip on hover
  $("#pageflip").hover(function() {
    $('.arrow').hide();
    $("#pageflip img , .msg_block").stop()
      .animate({
        width: '105px', 
        height: '105px'
      }, 500); 
    } , function() {
    $("#pageflip img").stop() 
      .animate({
        width: '50px', 
        height: '52px'
      }, 220);
    $(".msg_block").stop() 
      .animate({
        width: '50px', 
        height: '52px'
      }, 200);
  });
});

$(document).ready(function(){
//DASHBOARD: Arrows on hover
  $('#dashmap area').mouseenter(function() {
    showID = $(this).attr('class');
    $('.arrow').hide();
    $('#'+showID).show();
    });
});

$(document).ready(function(){
//DASHBOARD-GALLERY: OV on hover

});


$(document).ready(function(){
  $("#newsSlider").newsHPSlider({
    prevText:'UP',
    nextText:'DOWN',
    orientation:'horizontal',
    showElements:'2',
    nextButt:'teaser_pager_next',
    prevButt:'teaser_pager_prev'
  });
});

$(document).ready(function(){
  if($("#ncStartSegPol_ov").length == 0){
    countOv = $('.ncStartSegPol').length;
    for(i=0;i<countOv;i++){
      if(i!=0){
        $selectedNC = $('.ncStartSegPol:eq('+i+')').removeClass();
        $selectedNC.addClass('ncStartSegPol nc0'+(i));
      }
    }
    $('.ncStartSegPol').show();
  }
});