/* Copyright (C) 2007 - 2011 YOOtheme GmbH, YOOtheme Proprietary Use License (http://www.yootheme.com/license) */

(function($){

	$(document).bind('ready', function() {
		
		
		
		$('a[href="#demo"]').fancybox({
			scrolling: 'no',
			padding: 30,
			width: '350px',
			centerOnScroll: true
		});
		
		$('#hp-carousel').tabs({
			
		});

		// Accordion menu
		$('.menu-sidebar').accordionMenu({ mode:'slide' });

		// Dropdown menu
		$('#menu').dropdownMenu({ dropdownSelector: 'div.dropdown'});

		// Smoothscroller
		$('a[href="#totop"]').smoothScroller({ duration: 500 });

		// Fix Browser Rounding
		$('.grid-block').matchWidth('.grid-h');

		// Match height of div tags
		var matchHeight = function(){
			//$('#top-a .grid-h').matchHeight('.deepest');
			//$('#top-b .grid-h').matchHeight('.deepest');
			$('#bottom-a .grid-h').matchHeight('.deepest');
			$('#bottom-b .grid-h').matchHeight('.deepest');
			$('#innertop .grid-h').matchHeight('.deepest');
			$('#innerbottom .grid-h').matchHeight('.deepest');
			$('#maininner, #sidebar-a, #sidebar-b').matchHeight();
		};
		
		matchHeight();
		
		$(window).bind("load", matchHeight);
		
		$('#content h1, #content h2, #content h3, #content h4, #content h5, #content h6, .php_widget-13 h3').each(function(index) {
			//console.log($(this).text());
			twoColorTitles($(this));
		});
		
		$('.mod-explore-menu .menu > li').each(function(index) {
			var menutitleclass = $('> a', this).text().toLowerCase().replace(/ /g, '-');
			//console.log(menutitleclass);
			$(this).addClass(menutitleclass);
		});	
		
		$(".mod-explore-menu li.parent").hoverIntent(function(){  
			if($(".mod-explore-menu li.parent > ul.children").is(":visible")) {
			$(".mod-explore-menu li.parent > ul.children").each(function() {
				$(this).hide('blind', "fast");   				
			});
			}
			$(this).addClass("open");
   			$(this).children("ul.children").show('blind', "fast");   
  		}, function(){  
   			$(".mod-explore-menu li.parent.open > ul.children").each(function() {
				$(this).hide('blind', "fast");   				
			});  
			$(".mod-explore-menu li.parent.open").removeClass("open");   
  		});
		
	});
	
	function twoColorTitles(element) {
		//console.log(element);
			var twocolorelement = element;
			var twocolortitletext = twocolorelement.text();
			var twocolortitle = twocolortitletext.split('||');
			//console.log(twocolortitle[0]);
			//console.log(twocolortitle[1]);
			if(twocolortitle[1]) {
				twocolorelement.html('<span class="color">'+twocolortitle[0]+'</span>'+twocolortitle[1]);
			}
	}
	
})(jQuery);


