//**********************************************************************************************************************
/**
* COMPANY: Zipline Interactive
* EMAIL: infon@gozipline.com
* PHONE: 509-321-2849
* DESCRIPTION: This document contains programming required for the website templates.  Requires the jQuery library.
*/
//***********************************************************************************************************************

//CREATE HTML 5 STYLES
document.createElement('header');
document.createElement('nav');
document.createElement('section');
document.createElement('article');
document.createElement('aside');
document.createElement('footer');

var weather = 'closed';
var video = 'closed';

function load_big_video(vid) {

	$.post("#", { action: 'load_video', vid: vid, height: 227, width: 355 },function(data){

		$('#large-video').html(data);
			
	});	
}

var conditions_loaded = '';
var videos_loaded = '';

/************************************************************************
/ Open/close conditions
/************************************************************************/

function open_conditions() {
	if(conditions_loaded != 'loaded') {
		$('#conditions-wrapper').load('/index.php?action=output_home_conditions_skiidaho');
		conditions_loaded = 'loaded';
	}
	$('#conditions-popup').animate({ top: '0' },1000);
	$('#feature-conditions').css('background','url(/core/templates/skiidaho/web/images/bg-feature-conditions-hide.png) no-repeat');
	weather = 'open';
}

function close_conditions() {
	$('#conditions-popup').animate({ top: '325px' },1000);
	$('#feature-conditions').css('background','url(/core/templates/skiidaho/web/images/bg-feature-conditions.png) no-repeat');
	weather = 'closed';
}

/************************************************************************
/ Open/close videos
/************************************************************************/

function open_videos() {
	if(videos_loaded != 'loaded') {
		$('#videos-wrapper').load('/index.php?action=output_home_videos', function(response){
			load_big_video($('#thumbs_wrapper .popup-video-link').attr('rel'));
		});
		videos_loaded = 'loaded';
	} else {
		load_big_video($('#thumbs_wrapper .popup-video-link').attr('rel'));
	}
	$('#videos-popup').animate({ top: '0' },1000);
	$('#feature-videos').css('background','url(/core/templates/skiidaho/web/images/bg-feature-videos-hide.png) no-repeat');
	video = 'open';
}

function close_videos() {
	$('#videos-popup').animate({ top: '325px' },1000);
	$('#feature-videos').css('background','url(/core/templates/skiidaho/web/images/bg-feature-videos.png) no-repeat');
	$('#large-video').html('');
	video = 'closed';
}


//***********************************************************************************************************************
//ON DOCUMENT READY FUNCTIONS
//***********************************************************************************************************************
$(function() {
	
	/************************************************************************
	/ Preload images
	/************************************************************************/
	
	var image1 = $('<img />').attr('src', '/core/templates/skiidaho/web/images/bg-feature-conditions-hide.png');
	var image2 = $('<img />').attr('src', '/core/templates/skiidaho/web/images/bg-feature-videos-hide.png');

	
	/************************************************************************
	/ Newsletter signup 
	/************************************************************************/
	
	$('#search #text').click(function(){
	
		$(this).val('');
	
	});
	
	$('#search #text').blur(function(){
	
		if($(this).val() == '') {
			$(this).val('SIGN UP FOR OUR NEWSLETTER');
		}
	
	});
	
	/************************************************************************
	/ Homepage conditions tab
	/************************************************************************/
	
	$('.open-conditions').click(function(){
	
		if(weather == 'closed') {
			close_videos()
			open_conditions();
		}
		else {
			close_conditions();
		}

	});
	
	/************************************************************************
	/ Homepage videos tab
	/************************************************************************/
	
	$('.open-videos').click(function(){
			
		if(video == 'closed') {
			close_conditions();
			open_videos();
		}
		else {
			close_videos()
		}
					
	});
	
	$('.popup-video-link').live('click',function(){
	
		var vid = $(this).attr('rel');
		
		load_big_video(vid)
	
	});
	
	$.ajax({
		url: "/index.php",
		data: "action=output_home_random",
		success: function(result){
			$('#feature-conditions').append(result);
		}
	});

});


