// Avoid Script Conflicts
jQuery.noConflict();
// Encapsulation
(function($) {
	// Variables
	// Functions
	// Ready DOM
	$(function() {
		// Uniform
		$('select, input:checkbox').uniform();
		// Expanding Boxes
		$('.expand-box > li').each(
			function() {
				$('ul', $(this)).css({
					position: 'absolute'
				}).hide(0);
			}
		).hover(
			function() {
				return;
			},
			function() {
				$(this).removeClass('open');
				$('ul', $(this)).hide(0);
			}
		).children('a').click(
			function() {
				$(this).parents('li').toggleClass('open');
				$(this).siblings('ul').toggle(0);
				return false;
			}
		);
		
		var num = '1';
		sub_current = "btn_subcanvas1";
		
		switch_sub_canvas(sub_current);
		if(typeof current != 'undefined')
		{
			switch_canvas(current);
		}
		/*
jQuery('#canvas-nav li').mouseover(function(){
			if(this.id != current)
			{
				jQuery(this).toggleClass('canvas-nav-active');
			}
		});
		jQuery('#canvas-nav li').mouseout(function(){
			if(this.id != current)
			{
				jQuery(this).toggleClass('canvas-nav-active');
			}
		});
*/
		
		jQuery('#map-expanded-colapse span').click(function(){
			if(jQuery(this).attr('class') == 'close')
			{
				jQuery('#map-expanded-colapse span').removeClass('close');
				jQuery('#sub-page-map').slideDown();
				jQuery('#map-arrow').html('Close Map');
			}
			else
			{
				jQuery('#map-expanded-colapse span').addClass('close');
				jQuery('#sub-page-map').slideUp();
				jQuery('#map-arrow').html('View Map');
			}
		});
		
      // Equalize column heights
   
      /*
var tallestColumnHeight = 0;
      jQuery('#sub-page-content-left, #sub-page-content-right').each(function(){
      	var thisColumnHeight = jQuery(this).height();
      	tallestColumnHeight = (thisColumnHeight >= tallestColumnHeight) ? thisColumnHeight : tallestColumnHeight;
      }).css({height: tallestColumnHeight});
*/		
	});
})(jQuery);


function switch_sub_canvas(name) {
	control = "play";
	run_switch(name);
	jQuery('#sub-page-nav li').click(function(){
			//control = "stop";
			clearTimeout(run_loop);
			run_switch(this.id);
	});
	jQuery('.sub-page-canvas').mouseover(function(){
			control = "stop";
			clearTimeout(run_loop);
			run_switch(sub_current);
	});
	jQuery('.sub-page-canvas').mouseout(function(){
			control = "play"; // comment stop to stop play on click
			clearTimeout(run_loop);
			run_switch(sub_current);
	});
}

function run_switch(name)
{
	if(jQuery('#'+name).length > 0)
	{
		name = name.split('subcanvas');
		num = parseInt(name[1]);
	}
	else
	{
		num = 1;
	}
	now_name = 'btn_subcanvas'+num;
	if(now_name != sub_current)
	{
		jQuery('.sub-page-canvas').fadeOut('slow', function() {});
		jQuery('#subcanvas'+num).fadeIn('slow', function() {});
		jQuery('#sub-page-nav li').removeClass('sub-page-nav-active');
		jQuery('#btn_subcanvas'+num).addClass('sub-page-nav-active');
	}
	num = num + 1;
	sub_current = now_name;
	if(control != "stop")
	{
		run_loop = setTimeout(function(){
	        run_switch('btn_subcanvas'+num);
	    },8000);
    }
}

function switch_canvas() {
	control2 = "play";
	run_switch2(current);
	jQuery('#canvas-nav li').click(function(){
			//control2 = "stop";
			clearTimeout(run_loop2);
			run_switch2(this.id);
	});
}

function run_switch2(name2)
{
	var browserName=navigator.appName;
	if(jQuery('#'+name2).length > 0)
	{
		name2 = name2.split('btn_');
		num2 = parseInt(name2[1]);
	}
	else
	{
		num2 = 1;
	}
	now_name2 = 'btn_'+num2;
	if(now_name2 != current)
	{
		jQuery('#canvas-nav li').removeClass('canvas-nav-active');
		jQuery('#btn_'+num2).addClass('canvas-nav-active');
		if(browserName == "Microsoft Internet Explorer")
		{
			jQuery(".canvas-shell").hide();
			jQuery('#item_'+num2).show();
			jQuery(".rate-item").hide();
			jQuery('#rate_'+num2).show();
		}
		else
		{
			jQuery('.canvas-shell').fadeOut('slow', function() {});
			jQuery('#item_'+num2).fadeIn('slow', function() {});
			jQuery('.rate-item').fadeOut('slow', function() {});
			jQuery('#rate_'+num2).fadeIn('slow', function() {});
		}
	}
	num2 = num2 + 1;
	current = now_name2;
	jQuery('#canvas-nav li').mouseover(function(){
		if(this.id != current)
		{
			jQuery(this).addClass('canvas-nav-active');
		}
	});
	jQuery('#canvas-nav li').mouseout(function(){
		if(this.id != current)
		{
			jQuery(this).removeClass('canvas-nav-active');
		}
	});
	if(control2 != "stop")
	{
		run_loop2 = setTimeout(function(){
	        run_switch2('btn_'+num2);
	    },8000);
    }
}
