﻿$(document).ready(function(){

	//Load Features Widget

	$("div#insert-features").load('acc/acc_data.aspx', function(){

		featureControls();

	});

});



var featureControls = function(){



	//FEATURES

	//--------

	//Choose the feature to display

	var numItems = $("#feature_items>ul>li").length;

	var whichFeature;

	$("#feature_menu>ul>li").each(function(index) {

		if ( $(this).hasClass("sticky") ){ whichFeature = 0 }; 

	});

	if ( whichFeature ){}

	else { whichFeature = 0}; 	//No? Just choose a random one





	//Show that feature

	//In the menu

	$('#feature_menu>ul>li').css("height", "auto");  //The default CSS height is fixed to something reasonable for no JS support. With JS support, this line will simply allows Accordion to do its job.

	$('#feature_menu>ul').accordion({ active: whichFeature, autoHeight: true, fillSpace: true, collapsible: false, animated: 'easeOutExpo' });	

	$("#feature_menu>ul>li:eq("+ whichFeature +")").addClass("current");   //bg in menu

	//In the content

	$('#feature_items>ul>li').hide();

	$("#feature_items>ul>li:eq("+ whichFeature +")").show();

	

	//Click handler for displaying new content (accordion menu takes care of itself )

	$('#feature_menu>ul>li>h3').click(function(){

		var whichItem = $('#feature_menu>ul>li>h3').index(this);

		$('#feature_items>ul>li').hide();

		$("#feature_items>ul>li:eq("+ whichItem +")").show();

		$("#feature_menu>ul>li").removeClass("current");  //bg in menu

		$("#feature_menu>ul>li:eq("+ whichItem +")").addClass("current");   //bg in menu

	});





	//FEATURE  TYPES

	//--------------

	

	//GALLERY FEATURE

	//Set up vars

	var totalPics = $("ul.feature_gallery_IF>li").size();

	var thumbsShown = 10;

	thumbsShown -= 1;

	var activeThumbIndex = 0;

	var activePicture = 0;

	

	//GALLERY SETUP

	//Hide all but first full pic

	$("ul.feature_gallery_full>li").hide();

	$("ul.feature_gallery_full>li").eq(0).show();

	//Make thumbnail reflect choice

	$("ul.feature_gallery_IF>li").eq(0).addClass("active");

	//Hide all thumbs after "thumbsShown"

	$("ul.feature_gallery_IF>li:gt(" + thumbsShown + ")").hide();

	

	//When right scroll bar clicked

		//hide 0 slot of activeThumbs

		//unhide new one

	

	//Hide all pictures except 1

	//var pictures = $("ul.feature_gallery_IF>li").size();

	//alert(pictures);

	

	//Thumbnail clicks

	$("ul.feature_gallery_IF>li").click(function() {

	

		//THUMBNAILS

		$(this).siblings().removeClass("active");

		$(this).addClass("active");

	

		var which = $("ul.feature_gallery_IF>li").index(this);

		if ( which == activePicture ){} //if its the same pic, don't do anything man

		else {

			//NEW PIC

			//unhide picture

			$('ul.feature_gallery_full>li').eq(which).show();

			//put in in place, x and z axis

			$('ul.feature_gallery_full>li').eq(which).css({"right":"0", "z-index":"1000"});

	

			//OLD PIC

			//make sure its on top

			$('ul.feature_gallery_full>li').eq(activePicture).css({"z-index":"1001"});

			//slide oldpicture off, then hide it

			$('ul.feature_gallery_full>li').eq(activePicture).animate({right: "640px"}, 500, "easeInOutQuad", function(){

				$(this).hide();

			});

	

			//CAPTIONS

			//make sure it's on top

			//$('blockquote.feature_caption').css({"z-index":"1010"});

			//Replace caption

	

			//Process Complete

			activePicture = which;

		}

	});//thumbnail click

	

	

	//VIDEO FEATURE

	//Image to Video

	$('#feature_items>ul>li.feature_video>a.video_launch').click(function(){

		$(this).hide();

		$(this).parent().children("div.replace").show();

		$(this).parent().children("div.replace").css('z-index', 50);

		$(this).parent().children("blockquote").hide(); //blockquote

	});

	

	

	  //Brandbar DD

	  $("li.dropdown").click(function() {

		  $(this).children("ul.subnav").slideToggle(100);

	  });



}
