$(function () {
	
	// Cufon Font Replacement
    //Cufon.replace('figcaption');
    //Cufon.replace('nav li a', {
    //    hover: true
    //});
	
	// Language Select
	$(".dropdown dt a").click(function() {
		$(".dropdown dd ul").toggle();
		return false;
	});
				
	$(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
		$(".dropdown dt a span").html(text);
		$(".dropdown dd ul").hide();
		return false;
	});
				
	function getSelectedValue(id) {
		return $("#" + id).find("dt a span.value").html();
	}

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$(".dropdown dd ul").hide();
	});
	
	// Dropdown Menu
	function megaHoverOver(){
		$(this).find(".sub").stop().show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width() + 8; 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth();
			//Set Width
			$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().hide();
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
	


	//$("#navigation ul li .sub").css({'opacity':'0'});
	$("#navigation ul li").hoverIntent(config);
	
	$('#navigation li').mouseenter(function(){
		$(this).addClass("current");					
	});
	$('#navigation li').mouseleave(function(){
		$(this).removeClass("current");					
	});

	
	// Site Search
	var siteSearchFieldset = $('.kutuBodyArama');
	var siteSearchField = $('.kutuArama_aramaText input');
//	var selectedTitle = $('input[name="search_radio_group"]:checked').attr('title');
//	$(siteSearchField).attr("placeholder", selectedTitle);
	
	$(siteSearchField).addClass("idleField");  
	
    $(siteSearchField).focus(function() {  
        $(this).removeClass("idleField").addClass("focusField"); 
		$(siteSearchFieldset).removeClass("idleFieldset").addClass("focusFieldset");
    });
	
    $(siteSearchField).blur(function() {  
        $(this).removeClass("focusField").addClass("idleField");
    });
	
	$(siteSearchFieldset).click(function(event) {
		$('body').one('click',function() {
			$(siteSearchFieldset).removeClass("focusFieldset").addClass("idleFieldset");
		});

		event.stopPropagation();
	});
	
//	$('input[name="search_radio_group"]').change(function(){
//		selectedTitle = $(this).attr('title');
//		$(siteSearchField).attr("placeholder", selectedTitle);
//	});
	
	// Lightbox
	$(".lightbox").colorbox({
		opacity:0.75,
		current: "{current}/{total}"
	});
	
	$(".productImage li:eq(0)").addClass("active");
	$(".productImage ul a").click(function() {
		$(".productImage li").removeClass("active");
		$(this).parent().addClass("active");
		return false;
	});
	
});

$(function(){

	// Accordion
	$(".accordion").accordion({ 
		autoHeight: false, 
		header: "li a"
	});
	$(".accordion").last().accordion("option", "icons", false);

	// Tabs
	var $tabs = $('#tabs').tabs();
	$('.link-to-features').click(function() { // bind click event to link
		$tabs.tabs('select', 1); // switch to third tab
		$('html, body').animate({
			scrollTop: $("#tabs").offset().top
		}, 1000);
		return false;
	});
	
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
	
	// Button
	$("#divButton, #linkButton").button();
					
	// Icon Buttons
	$("#leftIconButton").button({
		icons: {
			primary: 'ui-icon-wrench'
		}
	});
	
	$("#bothIconButton").button({
		icons: {
			primary: 'ui-icon-wrench',
			secondary: 'ui-icon-triangle-1-s'
		}
	});					
	
	// Combinations
	$('#tabs2').tabs();
	$("#accordion2").accordion({ header: "h4" });
	$("#buttonInModal").button({
		icons: {primary: 'ui-icon-wrench'}
	});
	
	// Nested button tests
	$("#nestedButtonTest_1, #nestedButtonTest_2, #buttonInModal").button().click(function(e) {
		e.preventDefault();
	});
	
});





