$(document).ready(function() {
    /* Slider */
    $(".scroll").scrollable({
        size: 1,
        clickable: false,
        onLoad: function() {
            $('.next', '#scrollContainer').hide();
        },
        onBeforeSeek: function(e, i) {
            if (i == 9) {
                $('.next', '#scrollContainer').hide();
            }
            else {
                $('.next', '#scrollContainer').show();
            }
            //return false;
        }, // disables autoscroll
        onClose: function() {
            //unbind("onBeforeSeek"); // reenables autoscroll
        }
    })
	.circular().autoscroll({
	    steps: 1,
	    interval: 5000,
	    autopause: true
	});
    /* Tabs */
    $("ul.newstabsnav").tabs("div.newstabs > div", { current: 'selected' });

    /* Labelify */
    $("body.searchresultsPage #search .input").removeAttr('title');
    $("#search .input, #mailinglist #txtEmailAddress, #questionform .input").labelify();

    /* FAQ */
    $("#faq dd, #toptips dd").append('<br />&nbsp;').hide();
    $("#faq dt, #toptips dt").prepend('<img src="./sitefinity/media/images/arrow.png" alt="" class="faqarrow" /><span>More Info</span>');
    $("#faq dt:first-child, #toptips dt:first-child").css("background", "none")
    $("#faq dt span, #toptips dt span").click(function() {
        $('#faq dd:visible, #toptips dd:visible').slideUp('fast');
        $(this).parent().next('#faq dd, #toptips dd').slideDown('fast');
        $('#faq dd:visible, #toptips dd:visible').prev().toggleClass('nospan');
    });

    /* Stockist Map */
    $('h3#showmap').hide();
    $("h3.mapToggle").click(function() {
        $("#stockAll").slideToggle("slow");
    });
    $("h3#showmap").click(function() {
        $(this).hide();
        $("h3#hidemap").show();
    });
    $("h3#hidemap").click(function() {
        $(this).hide();
        $("h3#showmap").show();
    });

    /* Gallery Form */
    $('#gallery-form').hide();
    $("img#img1").click(function() {
        $("#gallery-form").slideToggle("slow");
    });

    /* Form Focus */
    $('#contactForm input[type="text"], #contactForm textarea').addClass("defaultField");
    $('#contactForm input[type="text"], #contactForm textarea').focus(function() {
        $(this).removeClass("defaultField").addClass("selectedField");
        if (this.value == this.defaultValue) {
            this.value = '';
        }
        if (this.value != this.defaultValue) {
            this.select();
        }
    });
    $('#contactForm input[type="text"], #contactForm textarea').blur(function() {
        $(this).removeClass("selectedField").addClass("defaultField");
        if ($.trim(this.value == '')) {
            this.value = (this.defaultValue ? this.defaultValue : '');
        }
    });

    /* Misc */
    // Add alternate table rows */
    $('#stockistsList tbody tr:odd').addClass('alt');
    // last class for news archive
    $(".newsarchive .item:last").addClass('last');

    /* Home Page SEO Text */
    $('#homecontent .text').hide();
    $('#homecontent #introtext').toggle(function() {
        $(this).addClass('close');
        $('#homecontent .text').slideDown();
    }, function() {
        $(this).removeClass('close');
        $('#homecontent .text').slideUp();
    });

    $("#wheretobuy a.idealworldReadmore").hover(function() {
        $('#idealWorldPopup').slideDown();
    },
  	function() {
  	    $('#idealWorldPopup').slideUp();
  	});

});


/*---------------------------------------------------------------------------------------
   Video
---------------------------------------------------------------------------------------*/
$(function() {
	$(".vid a").overlay({
		fixed: false,
		effect: 'apple',
		// when overlay is opened, load our player
		onLoad: function() { 
			this.getOverlay().find("a.player").flowplayer(0).load();
		},
		// when overlay is closed, unload our player
		onClose: function() { 
			$f().unload();
		}
	});
	// install flowplayer and activate ipad plugin
	$("a.player").flowplayer("./Sitefinity/media/jquery/flowplayer/flowplayer.red-3.2.5.swf");	
})

function menuActive() {
    $('#mainNav a').removeClass('selected');
    var pathName = window.location.pathname;
    i = pathName.lastIndexOf('/');
    pagename = pathName.substring(i + 1);
    $('a').each(function() {
        var linkHrf = this.href;
        i = linkHrf.lastIndexOf('/');
        linkName = linkHrf.substring(i + 1);
        if (linkName == pagename) {
            $(this).addClass("selected");
        }
    });
}
