
$(document).ready(function(){
	
//	/*Content Bölümündeki Slider*/
//$(function(){
//			$('#slides').slides({
//				preload: true,
//				generateNextPrev: true
//			});
//		});
	
	removeSearchValue();
	
	$("ul.headerNav > li > span:first").addClass("first");
	
	$("div.headersubNav ul").each(function(){
		
		$(this).find("li:last-child").addClass("last");
	
	});
	
	$("div.headerNav ul li").hover(function(){
		
		$(this).addClass("hover").find("div.headersubNav").show();
		
	},function(){
		
		$(this).removeClass("hover").find("div.headersubNav").hide();
		
	})
	
	/*Accordion Menu*/
	
	var slideBom = function (target) {
		$(target + " li a.activeLink").parent().addClass("activeLink");
	 	$(target + " li a.activeLink").next("ul").show();
		
        $(target + " li a").bind("click", function () {

            var targetLink = $(this);
            var object = targetLink.next();
			
			targetLink.parent().parent().find("li ul").slideUp();
			
            if (targetLink.parent().hasClass("activeLink")) {
                object.slideUp();
                targetLink.parent().removeClass("activeLink");
            }
            else {
                object.slideDown();
                targetLink.parent().parent().find("li").removeClass("activeLink");
                targetLink.parent().addClass("activeLink");
            }
        })
    }

    slideBom("div.sideBarInner ul");
	
	/*Accordion Menu*/
	
	/*ContentAccordion*/
	
	$("div.accordionTitle").click(function(){
		if ($(this).next().hasClass("open")) {
            $(this).removeClass("open").next().removeClass("open")
            }
		else {
			$("div.accordionEntry, div.accordionTitle").removeClass("open")
			$(this).addClass("open").next().addClass("open")
			}
		
		
		})
	
	
	
	/*LightBox*/
	

	/*LightBox*/
	
	$("a.lightboxImg").fancybox({
		'transitionIn'	:	'none',
		'transitionOut'	:	'none',
		//'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		"padding"		:	0,
		'width'			: 648,
		'height'		:380,
		//'type'			: 'iframe',
		"autoScale": false,
		"overlayOpacity":	0.8,
		"scrolling"		:	"no",
		
		onComplete: function(){
			
			$("#fancybox-wrap").css("width",$("#fancybox-wrap").width());
			$("#fancybox-wrap").css("height","362px");
			//$("#fancybox-content").css("height","380px").css("width","660px");
			$("#fancybox-content img").addClass("lightBoxImg");
			Cufon.replace('div.lightboxContentWrap h2', { fontFamily: 'DINPro-Bold', hover: true});
		
		}
	});	
	/*LightBox*/
	
	$("a.lightbox").fancybox({
		'transitionIn'	:	'none',
		'transitionOut'	:	'none',
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		"padding"		:	0,
		"autoScale": false,
		"overlayOpacity":	0.8,
		"scrolling"		:	"no",
		
		onComplete: function(){
			
			$("#fancybox-wrap").css("width",$("#fancybox-wrap").width()-18);
			$("#fancybox-wrap").css("height",$("#fancybox-wrap").height()-28);
			Cufon.replace('div.lightboxContentWrap h2', { fontFamily: 'DINPro-Bold', hover: true});
		
		}
	});	
	
	$("#various5").fancybox({
		'width'				:600,
		'height'			: 360,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		"scrolling"		:	"no",
		onComplete: function(){
			
			//$("#fancybox-wrap").css("width",$("#fancybox-wrap").padding()+18);
			$("#fancybox-wrap").css("height","360px");
			$("#fancybox-wrap").css("width",$("#fancybox-wrap").width()-20);
			Cufon.replace('div.lightboxContentWrap h2', { fontFamily: 'DINPro-Bold', hover: true});
		
		}
	});
	/*LightBox*/
	
	/*AddClass*/
$("div.content div.contentBoxes:last, div.sideBar div.sideBarInner ul li:last, div.newsContent ul li:last, div.productBoxes div.textArea ul li:last-child, div.sonucElement:last").addClass("last");
$("div.productBoxes:even").addClass("even");
$("div.portallarContent div.portallarBoxes:nth-child(3n)").addClass("noMargin");
$("div.detailContent div.detailInnerArea ul.referansMenu li:nth-child(4n)").addClass("noMargin");

 /*Tootip Footer*/
    $(".Tooltip").hover(function(){
        $(this).find("ul.department").show();
    },function(){
        $(this).find("ul.department").hide();
    });


Cufon.replace('ul.headerNav > li > span > a, .sliderContent .sliderInner h1, div.contentBoxes h1, div.detailCapital h1, div.loginWrap div.loginWrapInner h1, div.sideBarInner h1,  div.lightboxContentWrap h2, div.newsContentWrap h2', { fontFamily: 'DINPro-Bold', hover: true});
Cufon.replace('.sliderContent .sliderInner h2, div.contentBoxes h2, div.detailContent div.detailInnerArea h2', { fontFamily: 'DINPro-Medium', hover: true});


/*Hesabım Tabs Ui*/
		$( ".finansTabs" ).tabs();

//$(function(){
//			$('#slides').slides({
//				preload: true,
//				generatePagination: true,
//				generateNextPrev: true
//			});
//		});
		
		
		$(function(){
	
	
			var homeSliderLength = $("#slides").length;
			$("#numberBlock").text(homeSliderLength);
			
			// Set starting slide to 1
			var startSlide = 1;
			// Get slide number if it exists
			if (window.location.hash) {
				startSlide = window.location.hash.replace('#','');
			}
			// Initialize Slides
			$('#slides').slides({
				preload: false,
				generatePagination: true,
				generateNextPrev: true,
				play: 5000,
				pause: 2500,
				hoverPause: true,
				fadeSpeed: 350,
				//effect: 'fade',
				// Get the starting slide
				start: startSlide,
				animationComplete: function(current){
					var currentPageIndex = $("ul.pagination li.current").index();
					$("ul.pagination").animate({ top:(-40)*currentPageIndex },{ duration: 1000, easing: "easeOutBounce"})
				}
			});
		});
		
	
	/*HomePage Slider*/
		
		$(function(){
			$('#slider').anythingSlider();
		});
		
		/*Ajax Script*/		
		getData(1);	
})


/* searchValue remove */

function removeSearchValue(){

jQuery.fn.hint = function (blurClass) {
        if (!blurClass) {
            blurClass = 'blur';
        }

        return this.each(function () {
            // get jQuery version of 'this'
            var $input = jQuery(this),

            // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

            function remove() {
                if ($input.val() === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass);
                }
            }

            // only apply logic if the element has the attribute
            if (title) {
                // on blur, set value to title attr if text is blank
                $input.blur(function () {
                    if (this.value === '') {
                        $input.val(title).addClass(blurClass);
                    }
                }).focus(remove).blur(); // now change all inputs to title

                // clear the pre-defined text when form is submitted
                $form.submit(remove);
                $win.unload(remove); // handles Firefox's autocomplete
            }
        });
    };

    $(function () {
        $('input.textBox').hint();
    });
	
}


function getData(pageNumber) {	
	defaultParameters = "{pageNumber:" + pageNumber + "}";
	
	$(".loadingText").ajaxStart(function(){
		$(this).show();
		
	});
	
	$.ajax({
        type: "POST",
        url: "ajaxpage/indexhomesliderContentJSON.aspx",
        data: defaultParameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: (
			function(data) {
				
				var dataLength=data.NewList.length;
				var pageTotal =dataLength/3;
				
				if( pageTotal > parseInt(pageTotal) ){ pageTotal=parseInt(pageTotal)+1 }
				
			  $('#dataHomeSliderContent').setTemplateURL('ajaxpage/indexhomesliderContentTemplate.aspx', null, { filter_data: false });
			  $("#dataHomeSliderContent").setParam('pageNumber', pageNumber);
			  $("#dataHomeSliderContent").setParam('ItemQueue', (pageNumber-1)*3);
			  $("#dataHomeSliderContent").setParam('pageTotal', pageTotal);
			  $('#dataHomeSliderContent').processTemplate(data).fadeIn();
			  $("div.newsContent ul li:last").addClass("last");
			}
		)	  
	})
	
	$(".loadingText").ajaxStop(function(){
		$(this).hide();
	});
}
