/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/


// Set up browser sniffing
browserClass = $.browser.name + $.browser.versionX + $.os.name;
browserClass2 = $.browser.name + ($.browser.versionNumber + "").replace(".","-") + $.os.name;


// Activate Cufon
Cufon.replace('#content h2, #content h3, #content h4, #content p.intro', { fontFamily: 'Stag_QS_Content' });
Cufon.replace('#range_tabs h3, .subpage #content h2, .subpage #content h3', { fontFamily: 'Stag_QS_Content', textShadow: '#00163b 1px 1px' });
Cufon.replace('#header #nav li a, .landing #content .tabset', { fontFamily: 'Stag_QS_NavTabs', hover: true });

Cufon.replace('.facebook-link .desc', { fontFamily: 'Stag_QS_Content' });
Cufon.replace('.facebook-link .desc strong, .facebook-link .title', { fontFamily: 'Stag_QS_NavTabs' });


// Activate DD_belated PNG fixing
if (browserClass=="msie6win")
{
	DD_belatedPNG.fix('.landing #content .ausmade');
	DD_belatedPNG.fix('#image_deco div span');
	DD_belatedPNG.fix('.facebook-link');
	DD_belatedPNG.fix('ul.list_suits li');
	DD_belatedPNG.fix('ul.list_suits02 li');
	DD_belatedPNG.fix('.twopacks');
}


// jQuery functions that run on "dom ready"
var _jQueryLoaded = (typeof(jQuery) == "function");
if (_jQueryLoaded)
{
	$(document).ready(function()
	{	
		// Makes links open in new window when they have rel=external
		$("a[rel=external]").attr("target", "_blank");
		// Use below method if using thickbox, matches class rather than rel
		$("a.external-link").attr("target", "_blank"); 
		// Use below method if using thickbox, matches class rather than rel
		$("a.new-window")
			.click(function(evt){
				evt.preventDefault();
				function RandomId(){
					var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
					var string_length = 30;
					var randomstring = '';
					for (var i=0; i<string_length; i++) {
						var rnum = Math.floor(Math.random() * chars.length);
						randomstring += chars.substring(rnum,rnum+1);
					}
					return randomstring;
				}
				window.open(this.href,RandomId());
			})
		; 
		
		// Set up 'custom card' fader cycle
		$('html').removeClass("nojs");
		
		// Set up 'custom card' fader cycle
		$('#customcards_cycle')
			.cycle({ 
				fx: "fade", 
				sync: true,
				speed: 400,
				timeout: 3600,
				pause: true
			})
		;
		var PackPreviewWindowOpened = false;
		var PackPreviewWindow;
		$('#content a.tooltip_href').each(function(){
			$(this)
				.click(function(evt){
					evt.preventDefault();
					if ($("html").hasClass("opera"))
					{
						if (PackPreviewWindowOpened==true)
						{
							PackPreviewWindow.close();
							PackPreviewWindowOpened = false;
						}
						PackPreviewWindow = window.open(this.href,"PackPreviewWindow","width=300,height=300,resizable=no,scrollbars=notoolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,left="+Math.floor((screen.width/2)-(300/2))+",top="+Math.floor((screen.height/2)-(300/2))+"");
						PackPreviewWindow.focus();
						PackPreviewWindowOpened = true;
						$(window)
							.focus(function(){
								if (PackPreviewWindowOpened==true)
								{
									PackPreviewWindow.close();
									PackPreviewWindowOpened = false;
								}
							})
						;
					}
					return false;
				})
			;
			if (!$("html").hasClass("opera"))
			{
				$(this).append('<span class="tooltip"><img src="' + $(this).attr("href") + '" /></span>');
				if (browserClass=="msie6win") {
					$(this).html($(this).html().replace(/\.png/i,".gif"));
				}
				$(this)
					.each(function(){
						if (!$("html").hasClass("msie"))
						{
							$(".tooltip",this)
								.animate({ opacity: "0" },0)
							;
						}
					})
					.mouseover(function(){
						var HoverTopPosition = (0-$(".tooltip",this).height()-10);
						var HoverLeftPosition = (($(this).width()/2)-($(".tooltip",this).width()/2));
						if ($("html").hasClass("msie"))
						{
							$(".tooltip",this)
								.show()
								.css("left",HoverLeftPosition)
								.css("top",HoverTopPosition)
								.css("visibility","visible")
							;
						}
						else
						{
							$(".tooltip",this)
								.show()
								.css("left",HoverLeftPosition)
								.css("top",HoverTopPosition)
								.css("visibility","visible")
								.dequeue()
								.stop()
								.animate({ opacity: "1" },300,'linear',function(){
								})
							;
						}
					})
					.mouseout(function(){
						if ($("html").hasClass("msie"))
						{
							$(".tooltip",this)
								.hide()
								.css("visibility","hidden")
							;
						}
						else
						{
							$(".tooltip",this)
								.dequeue()
								.stop()
								.animate({ opacity: "0" },300,'linear',function(){
									$(this)
										.hide()
										.css("visibility","hidden")
									;
								})
							;
						}
					 })
				;
			}
			$(".tooltip",this)
				.mouseover(function(evt){
					evt.preventDefault();
					return false;
				})
				.mouseout(function(evt){
					evt.preventDefault();
					return false;
				})
				.mousemove(function(evt){
					evt.preventDefault();
					return false;
				})
				.click(function(evt){
					evt.preventDefault();
					return false;
				})
			;
		});


	});
}

function WrapTimesCharacters()
{
	// Wrap 'times' characters
	$("p").each(function(){
		OldHtmlNormal = $(this).html();
		OldHtmlEscaped = escape(OldHtmlNormal);
		NewHtmlEscaped = OldHtmlEscaped.replace('%D7','<span class="times_char">%D7</span>');
		NewHtmlNormal = unescape(NewHtmlEscaped);
		$(this).html(NewHtmlNormal);
	});
}
