// JS code for my Twitter Widget
$(document).ready(function() {
	$("#twitter").getTwitter({
		userName: "lojmann",
		numTweets: 5,
		loaderText: "Loading tweets...",
		slideIn: true,
		slideDuration: 750,
		showHeading: false,
		headingText: "Seneste Tweets...",
		showProfileLink: true,
		showTimestamp: false
	});
});
// END

// JS code for the Image Carosuel 
function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
jQuery(document).ready(function() {
	jQuery('#mycarousel').jcarousel({
		auto: 1,
        wrap: 'last',
        scroll: 1,
        size: 24,
        initCallback: mycarousel_initCallback
	});
});
// END

// JS code Google +1 button
window.___gcfg = {lang: 'da'};

  (function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();
 // END

// JS code to extend Google Analytics implementation
$(document).ready(function(){
	//loop though each anchor element
	$('a').each(function(){
		var href = $(this).attr('href');
		var filetypes = /\.(js|zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;

		//check for links starting with http or https, making sure that links to our own domain are excluded
		if ((href.match(/^https?\:/i)) && (!href.match(document.domain))){
			$(this).click(function() {
				var extLink = href.replace(/^https?\:\/\//i, '');
				_gaq.push(['_trackEvent', 'External', 'Click', extLink]);	
			});
		}
		//check for links starting with mailto:
		else if (href.match(/^mailto\:/i)){
			$(this).click(function() {
				var mailLink = href.replace(/^mailto\:/i, '');
				_gaq.push(['_trackEvent', 'Email', 'Click', mailLink]);
			});
		}
		//check for links with file extension that match the filetypes regular expression:
		else if (href.match(filetypes)){
			$(this).click(function() {
				var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
				var filePath = href.replace(/^https?\:\/\/(www.)lojmann\.dk\//i, '');
				_gaq.push(['_trackEvent', 'Download', 'Click : ' + extension, filePath]);
			});
		}
		//check for skype links
		else if (href.match(/^skype\:/i)){
			$(this).click(function() {
				var skypelLink = href.replace(/^skype\:/i, '');
				_gaq.push(['_trackEvent', 'Other Links', 'Skype', skypelLink]);
			});
		}
		//Check for ICQ links
		else if (href.match(/^icq\:/i)){
			$(this).click(function() {
				var icqlLink = href.replace(/^icq\:/i, '');
				_gaq.push(['_trackEvent', 'Other Links', 'ICQ', icqlLink]);
			});
		}
	});		
});
// END

