/*************************************************************************************************
Daily Telegraph NRL Team Statistics JS functions
author:		Andy Yip (andy.yip@dailytelegraph.com.au)
version:	1.0
date:		14/10/2011
copyright:	Nationwide News Pty Limited (News Limited) Copyright(c) 2011
*************************************************************************************************/
var IE7_PNG_SUFFIX = ".png";

(function ($) { 
    $.fn.Sportsman = function (options) {
        if (!this.length) { return; }

		// extending default values
        var o = $.extend({}, $.fn.Sportsman.defaults, options),
			$elems = this;

		function deviceCheck() {
			var ua = navigator.userAgent,
				mobile = ua.match(/(iPhone|iPod|iPad|BlackBerry|Android|webOS)/i),
				fileref,
				jQueryMobileJS = 'http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js',
				jQueryMobileCSS = 'http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.css',
				desktopCSS = 'css/desktop.css';
			
			if (mobile){
				// inject jquery mobile JS and CSS
				fileref=document.createElement('script');
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", jQueryMobileJS);
				fileref=document.createElement("link");
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", jQueryMobileCSS);
			}
			
			//if ($.browser.msie && parseInt($.browser.version) === 7) {

			//}
			
		}

	function openInNewWindow(url) {
		var newWindow = window.open(url, '_blank');
		newWindow.focus();
		return false;
	}
		
        return this.not(o.readyClass).each(function () {
			deviceCheck();

			$('.header').click(function() {
				window.location = o.urlPath;
			});
			
			$('.btn-subscribe').click(function() {
				openInNewWindow('http://thesportsman.newspaperdirect.com/epaper/viewer.aspx');
			});
			
			$('.btn-signup').click(function() {
				openInNewWindow('http://campaign.thesportsman.com.au/');
			});
			
			$('.btn-chartform').click(function() {
				openInNewWindow('chartform.html');
			});
		
			$('.btn-cameracharts').click(function() {
				openInNewWindow('cameracharts.html');
			});
			
			$('.btn-zipformratings').click(function() {
				openInNewWindow('zipform.html');
			});
			
			$('.btn-breedersguide').click(function() {
				openInNewWindow('breedersguide.html');
			});
			
			$('.btn-facebook').click(function() {
				openInNewWindow('https://www.facebook.com/pages/Sportsman/144782275573176');
			});
			
        }).addClass(o.readyClass);
    };

	// set defaults for main Sportsman function
    $.fn.Sportsman.defaults = {
		animate: false,
		wrap: true,
		wrapClass: "",
		urlPath: "index.html",
        readyClass: 'js-ready'
    };
		
	// call all functions with "#section-header" div
    $(function () {
		if ($('.wrapper').length) {
			$('.wrapper').Sportsman();
		} else {
			$('.wrapper2').Sportsman();
		}
    });
	

}(jQuery));



