var selectedItem = -1;

$.noConflict();
jQuery(document).ready(function($) 
{
	$("a[rel^='prettyPhoto']").prettyPhoto();
	
	
	if($('#sidebar').height() < $('#content').height())
	{
		$('#sidebar').css("height", $('#content').height());
		$('#leftSidebar').css("height", $('#content').height());
	}else
	{
		$('#content').css("height", $('#sidebar').height());
		$('#content').css("height", $('#leftSidebar').height());
	}
	
	$('ul.tabs').delegate('li:not(.current)', 'click', function() 
	{
		var i = $(this).index();
		$(this).addClass('current').siblings().removeClass('current');
		$(this).parents('div.tabsContainer').find('div.box').hide().eq(i).fadeIn(0);
		
	})
	
	jQuery("ul .sub .subMenu").hide();
	jQuery("ul .sub").mouseenter(
	function () 
	{
	
	jQuery(this).find('.subMenu').animate({
	  opacity: 0
	}, 0, function() {});
	
	jQuery(this).css("z-index", 4001);
	jQuery(this).find('.subMenu').toggle(0);
	
	jQuery(this).find('.subMenu').animate({
	  opacity: 1
	}, 200, function() {});
	
	}).mouseleave(function()
	{
	
	 jQuery(this).css("z-index", 1);
	 jQuery(this).find('.subMenu').toggle();
	  
	});
	
	
	$('ul .sub').each(function(index) 
	{
		$(this).find('.subMenu').css("width", 140);
		$(this).find('.subMenu').css("margin-left", -(70 - $(this).find("a").width() / 2));
	});
	
	$('.slide-out-div').tabSlideOut({
		tabHandle: '.handle',                              //class of the element that will be your tab
		imageHeight: '50px',                               //height of tab image
		imageWidth: '50px',                               //width of tab image    
		tabLocation: 'left',                               //side of screen where tab lives, top, right, bottom, or left
		speed: 300,                                        //speed of animation
		action: 'click',                                   //options: 'click' or 'hover', action to trigger animation
		topPos: '50px',                                   //position from the top
		fixedPosition: true                               //options: true makes it stick(fixed position) on scroll
	});
	
	$('.slide-out-div a.pattern-box').click(function (e) {
	
	      e.preventDefault();
	
	      var patternUrl = 'url(css/assets/pattern/' + $(this).attr('rel') + '.png)';
			
	      $('#body, html').css(
	
	          "background-image", patternUrl);
	
	      $.cookie("soul_cookie_bgimage",null);
	
	      $.cookie("soul_cookie_pattern", patternUrl)
	
	  });
	
	
	$('.toggle a').click(function (e) 
	{
	
		if($(this).find(".toggleIcon").hasClass("toggleIconOpen") || $(this).find(".toggleIconOpen").hasClass("toggleIconOpen"))
		{
			$(this).find(".toggleIconOpen").addClass("toggleIcon");
			$(this).find(".toggleIcon").removeClass("toggleIconOpen");
			
		}else 
		{
			
			$(this).find(".toggleIcon").addClass("toggleIconOpen");
			$(this).find(".toggleIcon").removeClass("toggleIcon");
			
		}
		
		$(this).parent().find('.toggleContent').slideToggle(500, function() {
		    
		    if($('#sidebar').height() < $('#content').height())
		    {
		    	$('#sidebar').css("height", $('#content').height());
		    	$('#leftSidebar').css("height", $('#content').height());
		    }else
		    {
		    	$('#content').css("height", $('#sidebar').height());
		    	$('#content').css("height", $('#leftSidebar').height());
		    }
		    
		    $('ul.tabs').delegate('li:not(.current)', 'click', function() 
		    {
		    	var i = $(this).index();
		    	$(this).addClass('current').siblings().removeClass('current');
		    	$(this).parents('div.tabsContainer').find('div.box').hide().eq(i).fadeIn(0);
		    	
		    })
		    
		});
		
		return false;
	});
	
	/***************************************************
				ACCORDION SLIDER
	***************************************************/
	jQuery.noConflict()(function($)
	{
		if ($('.kwicks').length)
		{
			$('.kwicks').kwicks({
				max : 840,
				spacing : 5
			});
		}
	});
		
		
	
	if ($('.prettyPhoto_hover').length)
	{
		jQuery(".prettyPhoto_hover").mouseover(
		function () 
		{
		
		 $(this).animate({
		   opacity: 0.8
		 }, 200, function() {});
		  
		}).mouseout(function()
		{
		
		    $(this).animate({
		      opacity: 1
		    }, 200, function() {});
		    
		});
	}
	
	if ($('#nivoSlider').length)
	{
		$('#nivoSlider').nivoSlider();
	}
	
	if ($('#slider').length)
	{
		$('#slider').nivoDragger(
	    {
	        effect: 'random', // Specify sets like: 'fold,fade,sliceDown'
	        controlsId: '.slider1',
	        slices: 15, // For slice animations
	        boxCols: 8, // For box animations
	        boxRows: 4, // For box animations
	        animSpeed: 800, // Slide transition speed
	        pauseTime: 5000, // How long each slide will show
	        startSlide: 0, // Set starting Slide (0 index)
	        directionNav: false, // Next & Prev navigation
	        directionNavHide: true, // Only show on hover
	        controlNav: true, // 1,2,3... navigation
	        controlNavThumbs: false, // Use thumbnails for Control Nav
	        controlNavThumbsFromRel: false, // Use image rel for thumbs
	        controlNavThumbsSearch: '.jpg', // Replace this with...
	        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
	        keyboardNav: true, // Use left & right arrows
	        pauseOnHover: true, // Stop animation while hovering
	        manualAdvance: false, // Force manual transitions
	        captionOpacity: 0.5, // Universal caption opacity
	        prevText: 'Prev', // Prev directionNav text
	        nextText: 'Next', // Next directionNav text
	        beforeChange: function(){}, // Triggers before a slide transition
	        afterChange: function(){}, // Triggers after a slide transition
	        slideshowEnd: function(){}, // Triggers after all slides have been shown
	        lastSlide: function(){}, // Triggers when last slide is shown
	        afterLoad: function(){} // Triggers when slider has loaded
	    });
				
	}	
});	


