jQuery(document).ready( function() {
    
	$('#accordion').accordion({
			autoHeight: false
		});

	
	Cufon.replace('h1, h2, h3, h4, h5, .mainTabsNav, #headerMenu a, .listbaslik, #leftMenuTitle, .sectiontitle, .slogan, .diavio, .section-title, #headerMenuContainer .level1a' , { fontFamily: 'DinB Medium', hover: true } );
	
	jQuery(".webSitesTitle a").attr("href","");
	
	jQuery("a[rel=saklamakosullari]").css("display","none");
	
	jQuery("#m_selected").parent().attr("id","m_selected_li");
	
	//if ( jQuery("#accordion").length > 0 )
	//{
		
		//jQuery("#accordion").accordion({
			//header: '.listbaslik',
			//active: '.selected',
			//autoheight: false,
			//alwaysOpen: false
		//});
	//}
	
jQuery("#mainTabsContent > div").css("display","none");

	var mainTabsNav = jQuery("#mainTabsNav").children("div");
	var mainTabsContent = jQuery("#mainTabsContent").children("div");	
	
	mainTabsNav.click( function() {
	
		var tabIndex = mainTabsNav.index(jQuery(this));
		mainTabsNav.removeClass("active");
		jQuery(mainTabsNav[tabIndex]).addClass("active");
		
		mainTabsContent.css("display","none");
		jQuery(mainTabsContent[tabIndex]).css("display","block");
		Cufon.refresh();
	
	});
	jQuery(mainTabsNav[0]).click();
	
	var fancyBoxImage = jQuery("a[rel=zoom]");
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	fancyBoxImage = jQuery("a.zoom");
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	fancyBoxImage = jQuery("a[rel=yoneticiCV]");
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'width'				: '90%',
			'height'			: '80%',
			'autoScale'     	: false

		});		
	}
	
	fancyBoxImage = jQuery("a[rel=saklamakosullari]");
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		});		
	}
	
	
	
	fancyBoxImage = jQuery(".urunler_b_gorsel_d").parent();
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	fancyBoxImage = jQuery(".urunler_b_gorsel_y").parent();
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	fancyBoxImage = jQuery(".urunler_b_foto_d").parent();
	
	if ( fancyBoxImage.length > 0 )
	{
		fancyBoxImage.fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
	}
	
	var smallProductPhotos = jQuery(".urunler_k_gorsel_d, .urunler_k_gorsel_y, .urunler_k_foto_d");
	var bigProductPhotos = jQuery(".urunler_b_gorsel_d, .urunler_b_gorsel_y, .urunler_b_foto_d");
	
	smallProductPhotos.each( function() {
		
		jQuery(this).parent().removeAttr("href");
		
	});
	
	smallProductPhotos.click( function() {
		
		var src = jQuery(this).attr("src");
		var alt = jQuery(this).attr("alt");
		bigProductPhotos.attr("src",src);
		bigProductPhotos.parent().attr("href",src);
		bigProductPhotos.attr("alt",alt);
		bigProductPhotos.parent().attr("title",alt);
		
	});
	
	var productNavLeft = jQuery("#productPicturesNavLeft");
	var productNavRight = jQuery("#productPicturesNavRight");
	var productNavPicturesWrapper = jQuery("#productPicturesNavPictures");
	var productNavPictures = jQuery(".productPicturesNavPictures");
	var productNavWidth = 0;
	var productNavCount = productNavPicturesWrapper.parent().width();
	var productNavTurn = 0;
	var productNavTurn2 = 0 ;
	
	productNavPictures.each( function() {
		
		productNavWidth += parseInt(jQuery(this).width()) + 50;
		
	});
	
	if ( productNavWidth % productNavCount != 0 )
	{
		 productNavTurn = parseInt(productNavWidth / productNavCount) + 1;
	}
	else
	{
		productNavTurn = parseInt(productNavWidth / productNavCount);
	}
	
	productNavLeft.click( function() {
		
		productNavTurn2--;
		if ( productNavTurn2 >= 0 )
		{
			productNavPicturesWrapper.animate({
				marginLeft: 0 - ( productNavCount * productNavTurn2 )							  
			},800);
		}
		else
		{
			productNavTurn2 = 0;
		}
	
	});
	
	productNavRight.click( function() {
		
		productNavTurn2++;
		if ( productNavTurn2 < productNavTurn )
		{
			productNavPicturesWrapper.animate({
				marginLeft: 0 - ( productNavCount * productNavTurn2 )							  
			},800);
		}
		else
		{
			productNavTurn2 = productNavTurn;
		}
	
	});
	
	productNavPictures.each(function() {
							
		jQuery(this).unwrap().unwrap();
	
	});
	
	jQuery(productNavPictures[0]).prev().remove();
	jQuery(productNavPictures[0]).unwrap().unwrap();
	
	jQuery(productNavPictures).find("a").each( function() {
		
		jQuery(this).removeAttr("href");
		
	});
	
	var bigproductPicture = jQuery("#productPicture img");
	var bigproductPictureTitle = jQuery("#productPictureTitle");
	
	productNavPictures.click( function() {
		
		var imagesrc = jQuery(this).find("img").attr("src");
		var summarytext = jQuery(this).attr("Summary") + "";
		
		bigproductPicture.attr("src",imagesrc);
		bigproductPictureTitle.html(summarytext);
		
	});
	
	jQuery(productNavPictures[0]).click();
	
	var productTabNav = jQuery("#yearTabNav").children("div");
	var productTabContent = jQuery("#yearTabContent").children("div");
	
	productTabNav.click( function() {
		
		productTabNav.removeClass("active");
		jQuery(this).addClass("active");
		Cufon.refresh();
		var tabindex = productTabNav.index(jQuery(this));
		
		//productTabContent.fadeOut(800);
		//jQuery(productTabContent[tabindex]).fadeIn(800);
		productTabContent.css("display","none");
		jQuery(productTabContent[tabindex]).css("display","block");
		
	});
	
	var brandLink = jQuery("#siteLinker").text();
	jQuery("#siteLink").attr("href","http://" + brandLink).text(brandLink);
	jQuery("#siteLinker").remove();
	
	var boxOpenerContent = jQuery(".boxOpenerContent");
	var boxOpener = jQuery(".boxOpener");
	var boxOpenerContentClose = jQuery(".boxOpenerContentClose");
	var boxOpenerIndex = 0;
	
	jQuery(".boxOpener").click( function() {
		
		boxOpenerIndex = boxOpener.index(jQuery(this));
		
		boxOpenerContent.css("display","none");
		jQuery(boxOpenerContent[boxOpenerIndex]).css("display","block");
		
	});
	
	boxOpenerContentClose.click( function() {
		
		jQuery(this).parents(".boxOpenerContent").css("display","none");
		
	});
	
	var mapyonetim = jQuery("#tbl1 tr");
	var sttout;
	var mapyonetim2 = jQuery("#tbl2 tr");
	
	
	if (mapyonetim.length > 0)
	{
		map(mapyonetim);
	}
	
	if (mapyonetim2.length > 0)
	{
		map2(mapyonetim2);
	}

	
	function map(asd)
	{	
		
		for( var i = 0; i < asd.length; i++  )
		{
			
			jQuery("#" + jQuery(asd[i]).attr("id") + "foto").css('display','none');
			jQuery(asd[i]).bind("mouseenter", function() {
				jQuery("#" + jQuery(this).attr("id") + "foto").css('display','block');
			});
			
			jQuery(asd[i]).bind("mouseleave", function() {
				jQuery("#" + jQuery(this).attr("id") + "foto").css('display','none');
			});
		}
	}
	
	function map2(asd2)
	{	
		
		for( var i = 0; i < asd2.length; i++  )
		{
			
			jQuery("#" + jQuery(asd2[i]).attr("id") + "foto").css('display','none');
			jQuery(asd2[i]).bind("mouseenter", function() {
				jQuery("#" + jQuery(this).attr("id") + "foto").css('display','block');
			});
			
			jQuery(asd2[i]).bind("mouseleave", function() {
				jQuery("#" + jQuery(this).attr("id") + "foto").css('display','none');
			});
		}
	}
	
});
