(function($) {
	
	$(function() {
		
		
		
		if ($('#subpage-banners > li').length > 1) {
			$('#subpage-banners').cycle();
		}
		
		$('#media-categories a').click(function() {
			var $a = $(this);
			var $div = $a.prev();
			
			var post_id = $(this).attr('post_id'),
				category_id = $(this).attr('category_id'),
				post_title = $div.find('.post_title').html(),
				post_content = $div.find('.post_title').html(),
				post_excerpt = $div.find('.post_excerpt').html();
			
			// show color box here
			
			var params = '/ajax/videos-list.php?category_id=' + category_id + '&post_id=' + post_id;
			
			$.colorbox({
				href: params,
				opacity: 0.3
			});
			
			return false;
		});
		
		$('a[href*=www.youtube.com/watch]').click(function() {
			
			var addr = $(this).attr('href')
			
			var video_id = addr.substr(addr.indexOf('?v=') + 3);
			video_id = video_id.substr(0, video_id.indexOf('&'));
			
			var iframe = '<iframe width="560" height="315" src="http://www.youtube.com/embed/' + 
				video_id + '" frameborder="0" allowfullscreen></iframe>';
			
			/*$.colorbox({
				href: '/ajax/youtube.php?url=' + encodeURI(addr),
				opacity: 0.3
			});*/
			
			return false;
		});
		
		if ($('.children .current_page_item').length > 0) {
			$('.current_page_item').parent().parent().addClass('current_page_item');
		}
		
		$('.validate-form').each(function() {
			return $(this).validate();
		});
		
		$('.validate-form input:text,.validate-form textarea').each(function() {
			$(this).attr('default_val', $(this).val());
		});
		
		$('.validate-form input:text,.validate-form textarea').focus(function() {
			var default_val = $(this).attr('default_val'), val = $(this).val();
			
			if (val == default_val) {
				$(this).val('');
			}
			
			$(this).addClass('focus');
			
		}).blur(function() {
			var default_val = $(this).attr('default_val'), val = $(this).val();
			
			if (val.length == 0) {
				$(this).val(default_val);
			}
			
			$(this).removeClass('focus');
		});
		
		// set font here
		Cufon.replace('.side_list', { fontFamily: 'MyraidPro-Regular',hover: true});
		Cufon.replace('.b_bar', { fontFamily: 'Helvetica Bold',hover: true});
		
		Cufon.replace('.exp_text', { fontFamily: 'MyraidPro-Regular',hover: true});
		Cufon.replace('#menu-header-menu > li > a', { fontFamily: 'MyraidPro-Regular', fontSize: '20px', hover: true});
		Cufon.replace('#menu-header-menu > li li a', { fontFamily: 'MyraidPro-Regular', fontSize: '16px', hover: true});
		
		Cufon.replace('.b_nav ul li a span', { fontFamily: 'MyraidPro-Regular',hover: true});
		Cufon.replace('.b_nav ul li a h4', { fontFamily: 'Helvetica Bold',hover: true});
		
		if (document.getElementById('default_products_page_container')) {
			Cufon.replace('#main-content h2:first', { fontFamily: 'MyraidPro-Regular',hover: true});
		} else {
			Cufon.replace('#main-content h2:not(#main-content ul h2)', { fontFamily: 'MyraidPro-Regular',hover: true});
		}
		
		Cufon.replace('#relevant-link-content', { fontFamily: 'MyraidPro-Regular',hover: true});
		
		Cufon.replace('.rightnav h3', { fontFamily: 'Helvetica Bold',hover: true});
		Cufon.replace('.rightnav ul li a', { fontFamily: 'Helvetica',hover: true});
		
		Cufon.replace('#service-times', { fontFamily: 'Helvetica'});
		Cufon.replace('#next-experience-time', { fontFamily: 'Helvetica',hover: true});
		
		if (document.getElementById('message-archives')) {
			
			/*$('.show-link a').click(function() {
				var $a = $(this);
				var $div = $a.prev();
				
				var post_id = $(this).attr('post_id'),
					category_id = $(this).attr('category_id'),
					post_title = $div.find('.post_title').html(),
					post_content = $div.find('.post_title').html(),
					post_excerpt = $div.find('.post_excerpt').html();
				
				// show color box here
				
				var params = '/ajax/videos-list.php?category_id=' + category_id + '&post_id=' + post_id;
				
				$.colorbox({
					href: params,
					opacity: 0.3
				});
				
				return false;
			});*/
			
			Cufon.replace('#message-archives li .show-name', { fontFamily: 'Helvetica'});
			Cufon.replace('#message-archives li .show-type', { fontFamily: 'Helvetica'});
			
			$('#message-archives .show-img').hover(function() {
				
				var $overlay = $(this).find('.show-overlay');
				
				$overlay.css({
					'opacity': 0
				});
				
				$overlay.animate({
									left: 0,
									opacity: 1
								},
								{
									duration: 350
								});
				
			}, function() {
				
				var $overlay = $(this).find('.show-overlay');
				
				$overlay.animate({
									left: -272,
									opacity: 0
								},
								{
									duration: 350
								});
				
			});
			
		}
		
		if (document.getElementById('home-buttons')) {
			Cufon.replace('#home-buttons a', { fontFamily: 'Helvetica Bold', hover: true});
			
			Cufon.replace('.home-event-date', { fontFamily: 'Helvetica Bold'});
			Cufon.replace('.home-event-title', { fontFamily: 'MyraidPro-Regular', hover: true});
		}
		
		if (document.getElementById('video-bar') || document.getElementById('video-details')) {
			Cufon.replace('#video-bar', { fontFamily: 'MyraidPro-Regular', hover: true});
			Cufon.replace('#video-details', { fontFamily: 'MyraidPro-Regular', hover: true});
		}
		
		if (document.getElementById('events-wrapper')) {
			Cufon.replace('.event-month-title', { fontFamily: 'Helvetica', hover: true});
			Cufon.replace('.date-number', { fontFamily: 'Helvetica Bold', hover: true});
			
			Cufon.replace('.event-information a', { fontFamily: 'Helvetica Bold', hover: true});
			
			Cufon.replace('.event-date', { fontFamily: 'Helvetica', hover: true});
			Cufon.replace('.event-location', { fontFamily: 'Helvetica', hover: true});
		}
		
		if (document.getElementById('collapsible-list')) {
			
			$('#collapsible-list li:first').addClass('first');
			$('#collapsible-list li:even').addClass('even');
			
			$('#collapsible-list li h2').hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			}).click(function() {
				
				if (!$(this).parent().is('.open')) {
					$('#collapsible-list li *:not(h2)').slideUp(400);
					$('#collapsible-list li.open').removeClass('open');
					
					$(this).parent().addClass('open');
					$(this).parent().find('*:not(h2)').slideDown(400);
				}
				
			});
		}
		
		if (document.getElementById('default_products_page_container')) {
			
		}
		
		$('#menu-header-menu > li').hover(function() {
			$(this).addClass('hover');
		}, function() {
			$(this).removeClass('hover');
		});
		
		$('#menu-footer-menu > li:last').addClass('li-last');
		
		
		$('#menu-header-menu .sub-menu').each(function() {
			$(this).find('.menu-item span').remove();
		});
		
		$('.leftside .innerbanner a[href*=youtube]').click(function() {
			var v = $(this).attr('href'), video_html;
			
			/*if (v.indexOf('embed') > -1) {
				video_html = '<iframe width="767" height="467" src="'+ v +'" frameborder="0" allowfullscreen></iframe>';
			} else {
				
				
				
				//v = v + '&autoplay=1';
				//video_html = '<object style="height: 467px; width: 767px"><param name="movie" value="'+ v +'"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed wmode="transparent" src="'+ v +'" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="767" height="467"></object>';
			}*/
			
			var addr = $(this).attr('href')
			
			var video_id = addr.substr(addr.indexOf('v=') + 2);
			
			if (video_id.indexOf('&') > -1) {
				video_id = video_id.substr(0, video_id.indexOf('&'));
			}
			
			video_html = '<object width="767" height="467"><param name="wmode" value="transparent"></param><param name="movie" value="http://www.youtube.com/v/'+ video_id +'?fs=1&amp;hl=en_US&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ video_id +'?fs=1&amp;hl=en_US&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="767" height="467" wmode="transparent"></embed></object>'
			
			var $parent;
			
			if ($(this).parent().is('.innerbanner')) {
				$parent = $(this).parent();
			} else {
				$parent = $(this).parent().parent().parent();
			}
			
			var close_button = '<a href="javascript:;" class="close-button">'
								+ '<img src="/wp-content/themes/tcos/resources/images/close-button.png" />'
								+ '</a>';
			
			video_html = '<div class="video_popup">' + close_button + video_html + '</div>';
			
			if ($parent.next().is('div.video_popup')) {
				$('div.video_popup').remove();
			}
			
			
			
			$(video_html).insertBefore( $parent );
			$('.innerbanner').hide();
			
			return false;
		});
		
		$('.close-button').live('click', function() {
			$('.video_popup').remove();
			$('.innerbanner').show();
			return false;
		});
		
		$('.sub-menu .current-menu-item').parent().parent().addClass('current-menu-item');
		
	});
	
})(jQuery);

setInterval('experience_clock();', 1000);

function experience_clock()
{
	var $ = jQuery;
	var $net = $('#next-experience-time');
	var days, hours, minutes, seconds;
	
	days = parseInt( $net.find('.days').attr('days') );
	hours = parseInt( $net.find('.hours').attr('hours') );
	minutes = parseInt( $net.find('.minutes').attr('minutes') );
	seconds = parseInt( $net.find('.seconds').attr('seconds') );
	
	if ((seconds - 1) < 0) {
		
		seconds = 59;
		
		if ((minutes - 1) < 0) {
			
			minutes = 59;
			
			if ((hours - 1) < 0) {
				
				hours = 23;
				
				if ((days - 1) < 0) {
					days = 0;
				} else {
					days -= 1;
				}
				
			} else {
				
				hours += 1;
				
			}
			
		} else {
			
			minutes -= 1;
			
		}
		
	} else {
		seconds -= 1;
	}
	
	$net.find('.days').attr('days', days);
	$net.find('.hours').attr('hours', hours);
	$net.find('.minutes').attr('minutes', minutes);
	$net.find('.seconds').attr('seconds', seconds);
	
	str = days;
	if (days < 10) {
		str = '0' + str;
		$net.find('.days').text(str);
	} else {
		$net.find('.days').text(str);
	}
	
	str = hours;
	if (hours < 10) {
		str = '0' + str;
		$net.find('.hours').text(str);
	} else {
		$net.find('.hours').text(str);
	}
	
	str = minutes;
	if (minutes < 10) {
		str = '0' + str;
		$net.find('.minutes').text(str);
	} else {
		$net.find('.minutes').text(str);
	}
	
	str = seconds;
	if (seconds < 10) {
		str = '0' + str;
		$net.find('.seconds').text(str);
	} else {
		$net.find('.seconds').text(str);
	}
	
	Cufon.replace('#next-experience-time', { fontFamily: 'Helvetica',hover: true});
}
