// Home page tabs function
$(document).ready(function(){

	$('#codeone_component_popular_tabs_content div').hide(); // Hide all divs
	$('#codeone_component_popular_tabs_content div:first').show(); // Show the first div
	$('#codeone_component_popular_tabs ul li:first').addClass('codeone_component_popular_tabs_selected'); // Set the class of the first link to active
	$('#codeone_component_popular_tabs ul li a').click(function(){ //When any link is clicked
		$('#codeone_component_popular_tabs ul li').removeClass('codeone_component_popular_tabs_selected'); // Remove active class from all links
		$(this).parent().addClass('codeone_component_popular_tabs_selected'); //Set clicked link class to active
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		$('#codeone_component_popular_tabs_content div').hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});

//set the display for page load
	$('.codeone_home_promo_left').hide();
	$('#codeone_home_promo_right div:first').append('<div id=\"overlay_white\">&nbsp;</div>');
  	$('#codeone_home_promo_content_left div:first').show();

// **** 
//homepage  rollovers
	$('#codeone_home_promo_right div').hover(function()
{
 $(this).append('<div id="home_promo_display">' + $('#' + this.id + ' img').attr('title') + '</div><div id=\"overlay\">&nbsp;</div>');
			 
}, 
function()
{
	 $('#home_promo_display').remove();
	 $('#overlay').remove();
			 	
});

// set the click action on the promos on the hompage.
	$('#codeone_home_promo_right div').click(function()
		  {
			  var current = $(this);		  
			  $('#codeone_home_promo_right #overlay_white').remove();
			  $(this).append('<div id=\"overlay_white\">&nbsp;</div>');
			  
			  $('.codeone_home_promo_left').animate({opacity: 0},300, function(){$('.codeone_home_promo_left').hide(); $('#' + current.attr('class')).show().animate({opacity: 100},300)});
			  
		  });
		
//Set the homepage news feeds to fade background colors
	$('.codeone_component_content_article_teaser').hover(function()
	  {
		  
	  	$(this).animate({ backgroundColor: "#faba27" }, 200)
	  },function()
	  {
		  if ($(this).parent().parent().css("background-color") != "transparent")
		  {
	  			$(this).animate({ backgroundColor: $(this).parent().parent().css("background-color")}, 200)
		  }
		  else
		  {
			  $(this).animate({ backgroundColor: $(this).parent().parent().parent().css("background-color")}, 200)
		  }
	  });
	//Set the homepage news feeds to fade background colors
	$('.codeone_component_content_news_teaser').mouseenter(function()
	  {
		  
	  	$(this).animate({ backgroundColor: "#faba27" }, 200)
	  }).mouseleave(function()
	  {
		  if ($(this).parent().parent().css("background-color") != "transparent")
		  {
	  			$(this).animate({ backgroundColor: $(this).parent().parent().css("background-color")}, 200)
		  }
		  else
		  {
			  $(this).animate({ backgroundColor: $(this).parent().parent().parent().css("background-color")}, 200)
		  }
	  });

//Set the homepage news feeds to fade background colors
	$('.codeone_component_content_photos_teaser').mouseenter(function()
	  {
		  
	  	$(this).animate({ backgroundColor: "#faba27" }, 200)
	  }).mouseleave(function()
	  {
		  if ($(this).parent().parent().css("background-color") != "transparent")
		  {
	  			$(this).animate({ backgroundColor: $(this).parent().parent().css("background-color")}, 200)
		  }
		  else
		  {
			  $(this).animate({ backgroundColor: $(this).parent().parent().parent().css("background-color")}, 200)
		  }
	  });
	
//Set the homepage news feeds to fade background colors
	$('.codeone_component_content_video_teaser').mouseenter(function()
	  {
		  
	  	$(this).animate({ backgroundColor: "#faba27" }, 200)
	  }).mouseleave(function()
	  {
		  if ($(this).parent().parent().css("background-color") != "transparent")
		  {
	  			$(this).animate({ backgroundColor: $(this).parent().parent().css("background-color")}, 200)
		  }
		  else
		  {
			  $(this).animate({ backgroundColor: $(this).parent().parent().parent().css("background-color")}, 200)
		  }
	  });

//Set the drop down list to post the page back with sort order
 $('#ddlSelectSort').change(function(){
   window.location.search = $.query.set("sortby",$('#ddlSelectSort :selected').val()).toString();
});
if ($.query.get("sortby").length > 0)
{
    $("#ddlSelectSort option[value=" + $.query.get("sortby") + "]").attr('selected', 'selected');
}
	


//set category selectors checkboxes
var subcategories = new Array();
var myQuery = $.query.get('subcategory').toString();
if (myQuery.indexOf(':') > -1)
{
	subcategories = myQuery.split(':');
}
else if (myQuery != '')
{
	subcategories[0] = myQuery;	
}
if (subcategories.length > 0)
{
	for (i = 0; i < subcategories.length; i++)
	{
		$("#categorySelectors input[value=" + subcategories[i] + "]").attr('checked', 'checked');
	}
}
else
{
	$("#categorySelectors input").attr('checked', 'checked');
}


$("#categorySelectors input").change(function(){
	myQuery = new String();										  
	$("#categorySelectors input:checked").each(function(){
			if (myQuery != '')
			{
				myQuery += ':' + $(this).val();	
			}
			else
			{
				myQuery = $(this).val();	
			}			
	})						
	window.location.search = $.query.set('subcategory', myQuery);
});


//set category selectors checkboxes
var contenttype= new Array();
var myQuery = $.query.get('contentType').toString();
if (myQuery.indexOf(':') > -1)
{
	contenttype= myQuery.split(':');
}
else if (myQuery != '')
{
	contenttype[0] = myQuery;	
}
if (contenttype.length > 0)
{
	for (i = 0; i < contenttype.length; i++)
	{
		$("#content_type_selectors input[value=" + contenttype[i] + "]").attr('checked', 'checked');
	}
}
else
{
	$("#content_type_selectors input").attr('checked', 'checked');
}

$("#content_type_selectors input").change(function(){
	myQuery = new String();										  
	$("#content_type_selectors input:checked").each(function(){
			if (myQuery != '')
			{
				myQuery += ':' + $(this).val();	
			}
			else
			{
				myQuery = $(this).val();	
			}			
	})						
	window.location.search = $.query.set('contentType', myQuery);
});

$("#magazine_articles_dropdown").change(function(){
  window.location.pathname = 'magazine_detail.html?item_id=' + $(this).val();
})



// Search Results Content Types

$('#search_contenttypes input').change(function(){
if ($(this).attr('checked'))
{
	switch($(this).val())
	{
	 	case 'Articles':
			$('#codeone_Search_Articles').show();
			break;
	 
		case 'News':
			$('#codeone_Search_News').show();
			break;
		case 'Videos' : 
		$('#codeone_Search_Galleries div.Videos').show();
		break;
	case 'Photos' :
		$('#codeone_Search_Galleries div.Photos').show();
		break;
	case 'Artwork' :
		$('#codeone_Search_Galleries div.Artwork').show();
		break;
	}   
}
else
{
	switch($(this).val())
	{
 	case 'Articles' :
		$('#codeone_Search_Articles').hide();
		break;
	
	case 'News':
		$('#codeone_Search_News').hide();
		break;
	
	case 'Videos' : 
		$('#codeone_Search_Galleries div.Videos').hide();
		break;
	case 'Photos' :
		$('#codeone_Search_Galleries div.Photos').hide();
		break;
	case 'Artwork' :
		$('#codeone_Search_Galleries div.Artwork').hide();
		break;
	}   
}

});


// thumbnail wrapper to control height - for Image galleries
 $("img.thumb").each(function(){
$(this).wrap('<div class="thumbnail_wrap" />');
});

//thumbnail wrapper for main listing pages
$(".thumbnail_mask img").each(function(){
 $(this).parent().css('background-image', 'url(' + $(this).attr('src') + ')');
$(this).hide();
});

}); //end of document.ready