/// <reference path="jquery-1.4.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />

$(document).ready(function () {
    $(".menu-left li:not(.active)").hover(function () {
        $(this).addClass("active");
    },
    function () {
        $(this).removeClass("active");
    });

    $(".menu li:not(.active)").hover(function () {
        $(this).addClass("active");
    },
    function () {
        $(this).removeClass("active");
    });

    $(".slideshow").cycle({ fx: 'fade' });




//    $(".arrow-left, .arrow-right").hover(
//         function () {
//             $(this).find("img").show();
//          
//         },
//         function () {
//             $(this).find("img").hide();
//         }
//    );

    $(".slideshow").cycle({ fx: 'scrollHorz' });

    $(".arrow-left").click(function () {

        $(".slideshow").cycle('resume');
        $(".slideshow").cycle('prev');
        $(".slideshow").cycle('pause');
    });
    $(".arrow-right").click(function () {
        $(".slideshow").cycle('resume');
        $(".slideshow").cycle('next');
        $(".slideshow").cycle('pause');
    });

	$(".info").each(function()
	{
		var info = $(this).html();
		info = linkify(info);
		$(this).html(info);
	});
   
});

function linkify(text){
    if (text) {
        text = text.replace(
            /((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
            function(url){
                var full_url = url;
                if (!full_url.match('^https?:\/\/')) {
                    full_url = 'http://' + full_url;
                }
                return '<a href="' + full_url + '">' + url + '</a>';
            }
        );
		text = text.replace(
            /([a-zA-Z_\-]+?@[a-zA-Z_\-]+?\.[a-zA-Z\-\.]{2,6})/gi,
            function(email){
                
                return '<a href="mailto:' + email + '">' + email + '</a>';
            }
        );
	
    }
    return text;
}

/* Google Maps integration -------------------------------------------------------------------------------------- */
function AttachGMap(address, infobox, id, form_id) {

	var geocoder = null;
	var map = null;

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById(id));

		// Add marker for store address
		var geocoder = new GClientGeocoder();
		var point = geocoder.getLatLng(address, function(point) {

			if (!point) {
				//alert(address + " not found");
				// address not found, make maps invisible
				$("#" + id).css("background", "#fff");

			} else {
				var marker0 = new GMarker(point);
				marker0.title = "";
				map.addOverlay(marker0);
				map.setCenter(point, 13);
				GEvent.addListener(marker0, "click", function() {
					// submit to maps.google.no
					document.getElementById(form_id).submit();
				});
			}

			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.addControl(new GScaleControl());
		});
	}

	// hide copyrightinfo on the bottom. I did this because it was too big and went outside designated area.
	//$("#" + id + " .gmnoprint,#" + id + " > div:last").css("display", "none");
}



// disable selecting
// $.disableSelection(selector)
jQuery.fn.extend({
	disableSelection: function() {
		this.each(function() {
			this.onselectstart = function() { return false; };
			this.unselectable = "on";
			jQuery(this).css('-moz-user-select', 'none');
		});
	}
});

// check if page has visible scrollbar
// $.hasScrollbar()
jQuery.fn.hasScrollbar = function() {
	var scrollHeight = this.get(0).scrollHeight;

	//safari's scrollHeight includes padding
	if ($.browser.safari)
		scrollHeight -= parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));

	if (this.height() < scrollHeight)
		return true;
	else
		return false;
}

// get width of scrollbar (varies between browsers)
function scrollbarWidth() {
	var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
	// Append our div, do our calculation and then remove it 
	$('body').append(div);
	var w1 = $('div', div).innerWidth();
	div.css('overflow-y', 'scroll');
	var w2 = $('div', div).innerWidth();
	$(div).remove();
	return (w1 - w2);
}
