
function initCufon() {
	Cufon.replace('.btn-buy', { fontFamily: 'Lucida Grande', hover: true });
	Cufon.replace('.panel strong, #content .add-block strong', { fontFamily: 'Lucida Grande', hover: true });
	Cufon.replace('.intro .title h1', { fontFamily: 'TradeGothicLTStd', hover: true });
	Cufon.replace('#star', { fontFamily: 'Helvetica Neue Lt Std Bold Cnd 77' });
	Cufon.replace('#star-int', { fontFamily: 'Helvetica Neue Lt Std Bold Cnd 77' });
	Cufon.replace('#.txt-box p', { fontFamily: 'Helvetica Neue Lt Std Bold Cnd 77' });
	Cufon.replace('#tickets_form h3', { fontFamily: 'TradeGothicLTStd', hover: true });
	Cufon.replace('#confirm_form h3', { fontFamily: 'TradeGothicLTStd', hover: true });
	Cufon.replace('#content h2, #sidebar h2', { fontFamily: 'TradeGothicLTStd', hover: true });
	Cufon.replace('.img-holder h3, .img-holder strong, .intro .add-box h2, .intro .add-box .countdown-holder h3, .intro .add-box .countdown-holder strong, .intro .add-box .countdown-box ul', { fontFamily: 'TradeGothicLTStd', hover: true });

}


$(document).ready(function() {
						   
	initCufon();
	
	if($('a.scrollToContent').length) {
		$('a.scrollToContent').click(function(e) {
			e.preventDefault();
			var destination = $('#content').offset().top;
			$('html:not(:animated),body:not(:animated)').animate({ scrollTop: destination-20}, 400 );
		});
		
	}
	
	if((location.href!="http://mslottery.com.au/") && (location.href!="http://mslottery.com.au/index.php") && (location.href!="http://www.mslottery.com.au/") && (location.href!="http://www.mslottery.com.au/index.php")) {
		setupExpandingDiv();
		
	}

/* social popup */
	$('.facebook_large, .twitter_large').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'),'Share','width=580,height=370,resizable=true,scrollbars=true');
		if($(this).hasClass('facebook_large')) {
			 _gaq.push(['_trackSocial', 'facebook', 'share']);
		} else  {
			 _gaq.push(['_trackSocial', 'twitter', 'tweet']);
		}
	
	});
	


	if($("ul#faqs").length)
	{
		$("ul#faqs li").find("a:first").click(function(e) { e.preventDefault(); toggleFaq(this) });
	}


	if($("#sold_out_early_overlay").length) {
		$("#sold_out_early_overlay").overlay({
				top: 90,
			// load it immediately after the construction
			load: true,
				mask: {
				color: '#000',
				loadSpeed: 200,
				opacity: 0.7
			}
		});
	}

	if($('div.gallery-box').length) {
		$('div.gallery-box').cycle({ 
				fx:     'fade', 
				speed:  600, 
				timeout: 0, 
				prev: 'a.small-prev',
				next: 'a.small-next'
		});
		
		$('div.gallery-box a').click(function() {
			//set current image to loading img
			$('div.ms_img img').attr('src','assets/templates/main/images/side/loading.gif');
			
			//prep new image from link
			var nimg = $(this).attr('href');
			
			//set img to new image
			$('div.ms_img img').attr('src',nimg);  
		});
	}
	
	if($('div.carousel-box').length) {
		$('div.carousel-box ul').cycle({ 
				fx:     'fade', 
				speed:  600, 
				timeout: 5000, 
				prev: 'a.arrow-prev',
				next: 'a.arrow-next'
		});
	}
	
	
	if($('.img-box img').length) {
		if($('.img-box img').length > 1) {
			var current_slide = 0; //top
			var next_slide = 1;
			setInterval(function() {			
				if(current_slide >= $('.img-box img').length) {
					current_slide = 0; //if the slide doesnt exist, then the slide is the first slide.
				}
				$('.img-box img:eq('+current_slide+')').animate({'opacity':'0'},800);
				
				if(current_slide+1 >= $('.img-box img').length) {
					next_slide = 0;
				} else {
					next_slide = current_slide+1;
				}
				$('.img-box img:eq('+next_slide+')').animate({'opacity':'1'},800);
				current_slide++;
				
			},4000);
		}
	}
		
});

$(function() {
	if($('.gallery-box').length) {
		$(".gallery-box a[rel]").overlay({effect: 'default'});
	}
	
	if($('.map-box').length) {
		$(".map-box a[rel]").overlay({effect: 'default'});
	}
	
	if($('.link-view').length) {
		$(".link-view a[rel]").overlay({effect: 'default'});
	}
	
	if($('.eb_pw').length) {
		$(".eb_pw a[rel]").overlay({effect: 'default'});
	}
	
	if($('.gp_pw').length) {
		$(".gp_pw a[rel]").overlay({effect: 'default'});
	}
});

function toggleFaq(link)
{
	var cFaq = $("a.faq_active");
	
	if(cFaq.length)
	{
		newFaq = $(link);
		selfFaq = false;
		if(newFaq.hasClass("faq_active"))
			selfFaq = true;

		cFaq.removeClass("faq_active");
		cFaq.parents("li:first").find("div.answer:first").slideUp(400, function() { if(!selfFaq) { showFaq(link); } });
	}
	else
		showFaq(link);
}

function showFaq(link)
{
	var link = $(link);
	
	link.addClass("faq_active");
	link.parents("li:first").find("div.answer:first").slideDown(400);
}

function setupExpandingDiv() {
	if(!$.browser.msie) {
		$('body').append('<div id="expanding_div"></div>');
		var fw = $(document).width()/2 - 500;	
		$('#expanding_div').css({'position':'absolute','top':'365px','z-index':'99','width':fw+'px','height':'42px','background':'rgba(0,0,0,0.60)'});
		
		$(window).resize(function() {
		
			var fw = $(document).width()/2 - 500;
			$('#expanding_div').css({'position':'absolute','top':'365px','z-index':'99','width':fw+'px','height':'42px','background':'rgba(0,0,0,0.60)'});
		
		});

	}
		
}
