/* Author: 

*/






(function ($) {

    $.site =
	{
	    functions:
		{
		    gotoURL: function (url) {
		        document.location = url;
		    },
		    countSlides: function (curr, next, opts) {
		        var cycleCount = 'Bild ' + (opts.currSlide + 1) + ' av ' + opts.slideCount;
		        $('.photo-cycle-nav .total').html(cycleCount);

		    },
		    showShadow: function (curr, next, opts) {

		    }
		}
	}

    jQuery.exists = function (selector) { return ($(selector).length > 0); }

    $("#mainmenu li.submenu > a").click(function () {
        // TODO: Check if another submenu is open, if so close if first. 
        var $this = $(this);
        var $ullist = $this.parent().find("ul");

        if ($this.is(".open")) {
            $ullist.hide();
            $this.parent().removeClass("active");
            $this.removeClass("open");
        } else {
            $ullist.show();
            $this.parent().addClass("active");
            $this.addClass("open");
        }
        return false;
    });

    $("body").click(function () {
        setTimeout("$('#mainmenu li.submenu ul').hide();", 150);
        $("#mainmenu a").removeClass("open");
        $("#mainmenu li").removeClass("active");
    });

    $("#toplinks .input-search").each(function () {
        $(this).focus(function () {
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function () {
            if (!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    });

    if ($.exists($(".photo-cycle-offer"))) {
        $(".photo-cycle-offer").cycle({
            fx: 'scrollHorz',
            randomizeEffects: false,
            delay: 1000,
            speed: jt.cycleChangeSpeed,
            timeout: jt.cycleSpeed,
            pause: 1,
            next: '.photo-cycle-next',
            prev: '.photo-cycle-prev'
            //after: $.site.functions.countSlides, 
            //before: $.site.functions.showShadow
        });

        $(".photo-cycle-prev").click(function () {
            return false;
        });
        $(".photo-cycle-next").click(function () {
            return false;
        });
    }
    if ($.exists($(".photo-cycle-offer-small"))) {
        $(".photo-cycle-offer-small").cycle({
            fx: 'scrollHorz',
            randomizeEffects: false,
            delay: 1000,
            speed: 1500,
            timeout: 0,
            pause: 0,
            next: '.photo-cycle-next',
            prev: '.photo-cycle-prev',
            after: $.site.functions.countSlides
            //before: $.site.functions.showShadow
        });

        $(".photo-cycle-prev").click(function () {
            return false;
        });
        $(".photo-cycle-next").click(function () {
            return false;
        });
    }


    $(".industry-content .box").each(function () {

        //$this = $(this);
        // $this.find("p:not(.tags, .read-more):gt(0)").addClass("hidden");
        //$(".industry-content .box").find(".hidden").parent().find("p.read-more").show();

    });
    $(".industry-content .box p.read-more a").click(function () {

        var trigger = $(this);
        var parent = $(this).parent().parent();

        var title = trigger.html();
        var fliptitle = trigger.data("fliptitle");

        if (parent.find('p.hidden').length > 0) {
            parent.find('p.hidden').addClass('open').removeClass('hidden');
            trigger.addClass("open");
        }
        else {
            parent.find('p.open').removeClass('open').addClass('hidden');
            trigger.removeClass("open");
        }

        trigger.data("fliptitle", title);
        trigger.html(fliptitle);
        return false;

        /*
        var trigger = $(this);
        var parent = $(this).parent().parent();

        var title = trigger.data("title");
        var fliptitle = trigger.data("fliptitle");

        if (typeof (title) == "undefined") {
            title = trigger.html();
            trigger.data("title", title);
        } else {
            title = trigger.data("title");
        }



        if (typeof (fliptitle) == "undefined") {
            fliptitle = title;
            trigger.data("fliptitle", fliptitle);
        } else {
            fliptitle = trigger.data("fliptitle");
        }

        if ($.exists($('.hidden', parent))) {
            trigger.addClass('open');
            trigger.html(fliptitle);
            $('.hidden', parent).removeClass('hidden');
        } else {
            trigger.removeClass('open');
            trigger.html(title);
            parent.find("p:not(.tags, .read-more):gt(0)").addClass("hidden");
        }

        //parent.find(".hidden").removeClass("hidden");
        //$(this).parent().remove();
        return false;
        */
    });
    $(".input-help").click(function () {
        $(".search-facts").toggle();
    });

    if ($.exists($(".feature-row"))) {
        var $this = $(".feature-row");
        var al = $this.find(".active").position();
        $this.find(".arrow").css("left", parseInt(al.left) + 10 + "px");
    }

    $(".icon-newsletter").click(function () {
        $(this).next().show();
        return false;
    });

    $(".quicklinks .item img, .quicklinks .item p").click(function () {
        var url = $(this).parent().find("h3 a").attr("href");
        $.site.functions.gotoURL(url);

    });


    $.cookies.set('samhallsessid', 'cookiename'); //A cookie by the name 'samhallsessid' now exists with the value 'cookiename'





})(jQuery);











