$(document).ready(function() {

    if (((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) == null) {
        $('#resellerFormLink').attr("href", "reseller_application_form_inline.html")
            .fancybox({
                "width"			: 400,
                "height"		: "90%",
                "autoScale"		: false,
                "transitionIn"		: "elastic",
                "transitionOut"		: "elastic",
                "type"			: "iframe",
                "titlePosition"		: "inside"
            });

        $('#resellerFormLink_products').attr("href", "reseller_application_form_inline.html")
            .fancybox({
                "width"			: 400,
                "height"		: "90%",
                "autoScale"		: false,
                "transitionIn"		: "elastic",
                "transitionOut"		: "elastic",
                "type"			: "iframe",
                "titlePosition"		: "inside"
            });

        if ($('.productFormLink').length) {
            $('.productFormLink').each(function() {
                $(this).attr("href", $(this).attr('href').replace(/forms\//, 'forms/inline-') )
                    .fancybox({
                        "width"			: 400,
                        "height"			: "90%",
                        "autoScale"			: false,
                        "transitionIn"		: "elastic",
                        "transitionOut"		: "elastic",
                        "type"			: "iframe"
                    });
            });
        }


        $(".fancybox").fancybox({
            "width"			: "85%",
            "height"			: "85%",
            "autoScale"			: false,
            "transitionIn"		: "fade",
            "transitionOut"		: "elastic",
            "type"			: "iframe"
        });


        $(".fancybox-img").fancybox({
            "autoScale"		: true,
            "transitionIn"		: "fade",
            "transitionOut"		: "fade",
            "type"			: "image",
            "titlePosition"		: "inside"
        });

        $(".fancybox-youtube").click(function() {
            $.fancybox({
                'padding'		: 0,
                'autoScale'		: false,
                'transitionIn'	: 'none',
                'transitionOut'	: 'none',
                'title'		: this.title,
                'width'		: 680,
                'height'		: 495,
                'href'		: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type'		: 'swf',
                'swf'		: {
                    'wmode'		: 'transparent',
                    'allowfullscreen'	: 'true'
                }
            });

            return false;
        });

    }





    $('.external').click(function(event) {
        event.preventDefault();

        window.open(this.href);
    });





    if ($('.rowLink').length) {
        $('.rowLink').css('cursor', 'pointer').each(function() {
            $(this).click(function() {
                $link = $('td:first', $(this)).find('a').attr('href');
                location.href = $link;
            });
        });
    }





    $('.jsLink').css('cursor', 'pointer').each(function() {
        $(this).click(function(event) {
            link = $('.target:first', $(this)).attr('href');
            if (link != null) {
                event.preventDefault();
                location.href = link;
            }
        });
    });



    $('.infoButton.jsLink').addClass('js');



    $('h1, h2, textarea, input, .pageIntro, .featureText, .rightFeature').corner('2px');
    $('th.left').corner('2px tl bl');
    $('th.right').corner('2px tr br');
    $('th.bottom').corner('2px bl br');


    $('.accordion').accordion({ collapsible: true, active:-1} );


    $.fn.randomiseList = function() {

		var i, a, b, t;
		for (i = 0; i < this.length-1; i++) {
			j = Math.floor(Math.random()*(1+i));  // choose j in [0..i]
			if (j != i) {
				b = this[i];
				a = this[j];
				var t = a.parentNode.insertBefore(document.createTextNode(''), a);
				b.parentNode.insertBefore(a, b);
				t.parentNode.insertBefore(b, t);
				t.parentNode.removeChild(t);
			}
		}

		return this;
	};

	$('ul.randomList li').randomiseList();





    //Hide (Collapse) the toggle containers on load
    $(".toggle_container").hide();

    //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
    $(".trigger").click(function(){
        $(this).toggleClass("active").next().slideToggle("slow");
        return false; //Prevent the browser jump to the link anchor
    });


    // Zebra tables
    $("table tr:nth-child(even)").addClass("striped");


	$('a').filter(function() { return this.href.match(/^http:\/\/.*\.provu\.co(?:\.uk|m)/) == null; }).click(function(e) {
		try {
			_gat._getTrackerByName()._trackEvent('Outbound Links', $(this).attr('href'));
		} catch (e) {}
	});

});
