
//<![CDATA[

jQuery(function ($) {
	
    var VuoCMS = {
        //For intro cloud based image
        fixSelected: function () {
            jQuery(".selected").children().addClass("selected");
        },
        //Image zoom
        fancybox: function () {
            jQuery("a[class^='fancybox']").fancybox({
                'overlayOpacity': 0.7,
                'overlayColor': '#000000',
                'zoomSpeedIn': 500,
                'zoomSpeedOut': 500,
                'imageScale': false,
                'centerOnScroll': false
            });
        },
        //For intro cloud based image
        fancyboxAjax: function () {
            jQuery("a[class^='fancybox-ajax']").live('mouseover mouseout', function (event) {
                if (event.type === 'mouseover') {
                    jQuery("a[class^='fancybox-ajax']").fancybox({
                        'overlayOpacity': 0.7,
                        'overlayColor': '#000000',
                        'zoomSpeedIn': 500,
                        'zoomSpeedOut': 500,
                        'imageScale': false,
                        'centerOnScroll': false
                    });
                }
            });
        },
        //Cufon font replacement
        cufon: function () {
            Cufon.replace('ul#nav_511697 a,ul#nav_524780', {
                textShadow: '1px 1px 0px #fff',
                hover: {
                    textShadow: '1px 1px 0px #fff'
                }
            })('#tagline,h3.hometitle,.entry h2.title,h1,.thumb_title,.comment-author,h3#comments,.entry h1, entry h2, h2, h3, .entry h4,h5,.price-boxes-style span, .entry h6,ul.planning h3', {
                textShadow: '2px 2px 2px rgba(0,0,0,0.2)'
            })('h4.widgettitle', {
                textShadow: '1px 1px 0px rgba(0,0,0,0.3)'
            });
            Cufon.now();
        },
        //Superfuck menu
        superfish: function () {
            jQuery('#nav_511697,#nav_524780').superfish({
				speed : 0,
                delay: 200,
                autoArrows: true,
                dropShadows: false
            });
        },
        //First page news scroll
        newsScroll: function () {
            if (jQuery('#blog').length) {
                jQuery('#blog').serialScroll({
                    target: '.recentscroll',
                    items: 'li',
                    prev: '#controllers2 a#right-arrow',
                    next: '#controllers2 a#left-arrow',
                    axis: 'y',
                    duration: 200,
                    force: true
                });
            }
        },
        //Zoom effect on functions
        portfolioZoom: function () {
            var $portfolioItem = jQuery('.item');
            $portfolioItem.hover(function () {
                $(this).find('.item-image').stop(true, true).animate({
                    top: -10
                }, 300);
            }, function () {
                $(this).find('.item-image').stop(true, true).animate({
                    top: 0
                }, 300);
            });
        },
        //For tabs on costs and order form.
        generalTabs: function () {
            $("ul.tabs").tabs("div.panes > div", {
                history: true
            });
			$("ul.tabs-sub").tabs("div.panes-sub > div", {
                history: false
            });
        },
        //Rounded corners on everything
        roundedCorners: function () {
            settings = {
                tl: {
                    radius: 0
                },
                tr: {
                    radius: 0
                },
                bl: {
                    radius: 10
                },
                br: {
                    radius: 10
                },
                antiAlias: true,
                autoPad: true,
                validTags: ["div"]
            };
            $('ul#nav_511697 ul,ul#nav_524780 ul,#login-wrapper').corner(settings);
        },
        //Partner nav.
        costsPresentationNav: function () {
            $('.info-trigger').live('mouseover mouseout', function (event) {
                //Find the class to trigger
                var infoClass = $(this).attr('data-info');
                if (event.type === 'mouseover') {
                    //remove any current hover from nav
                    $(this).parent(".pricing-features").children("li").removeClass("hover");
                    //Add the current nav hover
                    $(this).addClass("hover");
                    //Remove any current default info-default
                    $("." + infoClass + "").parent(".pricing-thumb").children("div").removeClass("default");
                    //Add current info-default
                    $("." + infoClass + "").addClass("default");
                }
				});
        },
        introVideoplayer: function () {
            $("#video-1").click(function () {
                $("#video-1").hide();
                var player = $f("player", "/swf/flowplayer-3.2.5.swf", {
                    clip: {
                        // the bitrates, video width and file names for this clip
                        bitrates: [{
                            url: "/Videos/Vuo-CMS-Plattformen-for-foretag-480P.mp4",
                            width: 480,
                            bitrate: 700
                        }, {
                            url: "/Videos/Vuo-CMS-Plattformen-for-foretag-720P.mp4",
                            width: 720,
                            bitrate: 2400
                        }, {
                            url: "/Videos/Vuo-CMS-Plattformen-for-foretag-1080P.mp4",
                            width: 1080,
                            bitrate: 4200
                        }],
                        urlResolvers: 'bwcheck',
                        baseUrl: '/'
                    },
                    onFinish: function () {
                        $("#video-div").remove();
                        $("#controllers-wrapper").show();
                        $('html,body').animate({
                            scrollTop: 0
                        });
                        $("#controllers .slide-nav").tabs("div.slides > div", {
                            // enable "cross-fading" effect 
                            effect: 'ajax',
                            // start from the beginning after the last tab 
                            rotate: true,
                            history: true,
                            current: 'active',
                            onAfter: function (i) {
                                var pane = this.getPanes("div.slides > div");
                                pane.html('<img src="/images/ajax-loader.gif" />');
                                pane.load(this.getTabs().eq(i).attr("href"));
                            }
                            // use the slideshow plugin. It accepts its own configuration 
                        }).slideshow({
                            autoplay: true,
                            clickable: false,
                            interval: 7000,
                            autopause: true,
                            next: '#right-arrow',
                            prev: '#left-arrow'
                        });
                    },
                    plugins: {
                        bwcheck: {
                            url: '/swf/flowplayer.bwcheck-3.2.3.swf',
                            netConnectionUrl: '/swf/flowplayer-3.2.5.swf'
                        },
                        controls: {
                            autoHide: true
                        }
                    }
                });
                player.play();
            });
        },
        //All tooltip functions
        tooltips: function () {
            //fade content on tooltip hover
            $("#recent-posts-3 ul,.portfolio-feature").hover(

            function () {
                $("#left-area,.portfolio-main").addClass("post-opacity");
            }, function () {
                $("#left-area,.portfolio-main").removeClass("post-opacity");
            });
            //fix menu missing a title attribute.
            $(".tooltip").attr('title', ' ');
            //load function description via ajax and add to tooltip.
            $(".tooltip").tooltip({
                predelay: 200,
                tipClass: 'tooltip-left',
                onBeforeShow: function () {
                    this.getTip().html("Laddar...");
                    theUrl = this.getTrigger().children("a").attr("href");
                    this.getTip().load(theUrl + " #funktion-description");
                },
                onHide: function () {},
                position: "center left",
                offset: [10, 0]
            });
            $(".tooltip2[title]").tooltip({
                predelay: 200,
                tipClass: 'tooltip-right',
                position: "center right"
            });
            $(".tooltip3[title]").tooltip({
                predelay: 200,
                tipClass: 'tooltip-left',
                position: "center left"
            });
            $(".tooltip-top[title]").tooltip({
                predelay: 500,
                tipClass: 'tooltip-center',
                position: "top center",
                offset: [25, 0],
                onBeforeShow: function () {
                    this.getTip().html("Laddar...");
                    theUrl = this.getTrigger().attr("href");
                    this.getTip().load(theUrl + " #funktion-description");
                },
                onHide: function () {

                }
            });
            // hide tooltip when hovering over it.
            $('.tooltip-dynamic').live('mouseenter', function () {
                $(this).hide();
            });
            /*$(".item").mouseenter(function () {
                $(".item").not(this).css('opacity', '0.3');
            }).mouseleave(function () {
                $(".item").not(this).css('opacity', '1');
            });*/
            $(".tooltip-functions[title]").tooltip({
                predelay: 100,
                tipClass: 'tooltip-dynamic',
                position: 'center right',
                onBeforeShow: function () {
                    theUrl = this.getTrigger().attr("rel");
                    $("<img>").appendTo(this.getTip()).attr('src', theUrl);

                },
                onHide: function () {
                    this.getTip().html(" ");
                }
            }).dynamic({
                bottom: {
                    direction: 'down',
                    bounce: true
                }
            });
        },
        ajaxSliderTabs: function () {
            var $featured = $('#featured'),
                $featured_content = $('#slides');
            //If the slider exists, start it.
            if ($featured_content.length) {
                $('div.slide .description').css('opacity', '0');
                $("#slide-button").click(function () {
                    //Remove the video player
                    $("#video-div").remove();
                    //Show controls for slideshow
                    $("#controllers-wrapper").show();
                    //Initiate the fucking ajax tabs
                    $("#controllers .slide-nav").tabs("div.slides > div", {
                        effect: 'ajax',
                        rotate: true,
                        history: true,
                        current: 'active',
                        onAfter: function (i) {
                            var pane = this.getPanes("div.slides > div");
                            pane.html('<img src="/images/ajax-loader.gif" />');
                            pane.load(this.getTabs().eq(i).attr("href"));
                        }
                        // use the slideshow plugin. It accepts its own configuration 
                    }).slideshow({
                        autoplay: true,
                        clickable: false,
                        interval: 7000,
                        autopause: true,
                        next: '#right-arrow',
                        prev: '#left-arrow'
                    });
                });
                //description fade-in / out
                $('#slides').live('mouseover mouseout', function (event) {
                    if (event.type === 'mouseover') {
                        $(".description").stop().show();
                    } else {
                        $(".description").stop().hide();
                    }
                });
            }
        },
        //Swap searchfield values
        swapInput: function () {
            var swapselectors = '#searchinput,.swapinput';
            jQuery(function ($) {
                swapValues = [];
                $.fn.inputswap = function () {
                    $(this).each(function (i) {
                        swapValues[i] = $(this).val();
                        $(this).focus(function () {
                            if ($(this).val() === swapValues[i]) {
                                $(this).val("");
                            }
                        }).blur(function () {
                            if ($.trim($(this).val()) === "") {
                                $(this).val(swapValues[i]);
                            }
                        });
                    });
                };
                $(swapselectors).inputswap();
            });
        },
        uniform: function () {
            $(function () {
                $("input:checkbox, input:radio, input:file").uniform();
            });
        },
        loggedInVariable: function () {
            if ($('#islogged').hasClass('islogged1')) {
                $(".hideiflogged").hide();
            }
            if ($('#islogged').hasClass('islogged0')) {
                $(".showiflogged").hide();
            }
            $('.whosloggedin').html($('#whosloggedin').html());
        },
        loggin: function () {
            $(".signin").live('click', function (e) {
                e.preventDefault();
                $("#login-wrapper").toggle();
                $(".signin").toggleClass("menu-open");
            });
			
			
			/*$(".signin").tooltip({ 

			   //the trick is to set it like this
			   events: {def: "click,''"},
			   position: "bottom left",
			   //the tip content
			   tip: '#login-wrapper', 
			   offset: [0, 0],
			   //the effect
			   effect: 'toggle'
			});*/
        },
		webappHide: function () {
		if ($('#islogged').hasClass('islogged0')) {
			//not logged in? Then do nothing.
            } else {
			if ($('#is-landingpage').length) {
				//only post if it's the landing page.
				if ($('#edit').length) {
					//only post if there is no current form available.
					}
					else {
						$('#form-start').css('display','block');
						$('#webapp-list').css('display','none');
						
						var ItemName = $("input#ItemName").val();
						var dataString = 'ItemName='+ ItemName;
						$.ajax({
						  type: "POST",
						  url: "/CustomContentProcess.aspx?CCID=3973&amp;OID={module_oid}&amp;OTYPE={module_otype}",
						  data: dataString,
						  success: function() {
							location.reload();
						  }
						 });
				}//third
				
			}//second
 
		  }//first
		}
    };
	
    VuoCMS.fixSelected();
    VuoCMS.fancybox();
    VuoCMS.fancyboxAjax();
    VuoCMS.superfish();
    VuoCMS.newsScroll();
    VuoCMS.portfolioZoom();
    VuoCMS.generalTabs();
    VuoCMS.roundedCorners();
    VuoCMS.costsPresentationNav();
    VuoCMS.introVideoplayer();
    VuoCMS.tooltips();
    VuoCMS.ajaxSliderTabs();
    VuoCMS.swapInput();
    VuoCMS.uniform();
    VuoCMS.loggin();
    VuoCMS.loggedInVariable();
	VuoCMS.webappHide();
    VuoCMS.cufon(); // Måste köras sist!
	
});
