function mycarousel_initCallback(carousel){
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_initCallback2(carousel) {
    $("#slogancarousel li").each(function() {
        $(".mycarousel-no").append('<a href="#">' + $(this).attr('jcarouselindex') + '</a>');
    });
    jQuery('.mycarousel-no a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
		  //carousel.startAuto(0);
        return false;
    });
    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });
    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function mycarousel_initCallback3(carousel) {
	 $("#aboutcarousel li").each(function() {
        $(".mycarousel-txt").append('<a href="#" title="' + $(this).attr('jcarouselindex') + '">' + $(this).find('h2').text() + '</a>');
    });
    jQuery('.mycarousel-txt a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('title')));
        return false;
    });
};

function highlight(carousel, obejctli,liindex,listate){
     jQuery('.mycarousel-no a:nth-child('+ liindex +')').attr("class","selected");
};
function removehighlight(carousel, obejctli,liindex,listate){
     jQuery('.mycarousel-no a:nth-child('+ liindex +')').removeAttr("class","selected");
};
// ABOUT
function highlightxt(carousel, obejctli,liindex,listate){
     jQuery('.mycarousel-txt a:nth-child('+ liindex +')').attr("class","selected");
};
function removehighlightxt(carousel, obejctli,liindex,listate){
     jQuery('.mycarousel-txt a:nth-child('+ liindex +')').removeAttr("class","selected");
};

jQuery(document).ready(function() {
	
    jQuery('#refwidgetcarousel').jcarousel({
        //auto: 2,
        wrap: 'both',
		  scroll: 1,
		  visible: 5
    });
	 
    jQuery('#slogancarousel').jcarousel({
        auto: 0,
        wrap: 'both',
		  scroll: 1,
		  size: $("#slogancarousel img").length,
		  buttonNextHTML: null,
        buttonPrevHTML: null,
		  initCallback: mycarousel_initCallback2,
		  itemVisibleInCallback: highlight,
		  itemVisibleOutCallback: removehighlight
    });
	 
	 jQuery('#aboutcarousel').jcarousel({
        //auto: 3,
        //wrap: 'both',
		  scroll: 1,
		  size: $("#aboutcarousel li").length,
		  buttonNextHTML: null,
        buttonPrevHTML: null,
		  initCallback: mycarousel_initCallback3,
		  itemVisibleInCallback: highlightxt,
		  itemVisibleOutCallback: removehighlightxt
    });
	 
	 $("#refcarousel li:empty").remove();
	 if ($("#refcarousel img").length) { 
		 jQuery('#refcarousel').jcarousel({
			  auto: 4,
			  size: $("#refcarousel img").length,
			  wrap: 'both',
			  scroll: 1,
			  //visible: 1,
			  initCallback: mycarousel_initCallback
		 });
	 } else{
		 $("#refcarousel").hide();
	 }
	 if ($("#refcarousel img").length == 1) { 
		 $(".jcarousel-prev").hide();
		 $(".jcarousel-next").hide();
	 } 
	 
	 $("#uruncarousel li:empty").remove();
	 if ($("#uruncarousel img").length) { 
		 jQuery('#uruncarousel').jcarousel({
			  auto: 4,
			  size: $("#uruncarousel img").length,
			  wrap: 'both',
			  scroll: 1,
			  //visible: 1,
			  initCallback: mycarousel_initCallback
		 });
	 } else{
		 $("#uruncarousel").hide();
	 }
	 if ($("#uruncarousel img").length == 1) { 
		 $(".jcarousel-prev").hide();
		 $(".jcarousel-next").hide();
	 } 
});


$(document).ready(function () {
	//alert(modsiteurl);
	if(jslang == 'TR') {
		$(".date").each(function() {
			var fname = $(this).text().split('-');					 
			switch(fname[1]) {
					case "Jan": caption= "Ocak";break;
					case "Feb": caption= "Şubat";break;
					case "Mar": caption= "Mart";break;
					case "Apr": caption= "Nisan";break;
					case "May": caption= "Mayıs";break;
					case "Jun": caption= "Haziran";break;
					case "Jul": caption= "Temmuz";break;
					case "Aug": caption= "Ağustos";break;
					case "Sep": caption= "Eylül";break;
					case "Oct": caption= "Ekim";break;
					case "Nov": caption= "Kasım";break;
					case "Dec": caption= "Aralık";break;
					//default: caption ="default";
			  }
			$(this).text(fname[0] + ' ' + caption + ' ' + fname[2])
		});
		$(".langlink").attr('href', modsiteurl.replace('http://www', 'http://en'));
		$('.hidsubs #CaptchaV2').val("Güvenlik Resmini Giriniz");;
	} else {
		$(".ikilan label").text('APPLY');
		$(".leftnews").prev().text('News');
		$(".langlink").attr('href', modsiteurl.replace('http://en', 'http://www'));
		$('.hidsubs #CaptchaV2').val("Enter Word Verification");
	}


	var qssp;
	if (location.href.indexOf("?") != -1) { 
		qssp = '&'; 
	} else {
		qssp = '?';  
	}	
	if ($(".newsredirect").length) { 
		if(jslang == 'TR') {
			document.location = $(".newsredirect a").attr("href") + qssp + 'CategoryID=32978';
		} else {
			document.location = $(".newsredirect a").attr("href") + qssp + 'CategoryID=35549';
		}		 
	}	
	if ($(".leftnews").length) { 
		$(".leftnews a").each(function() {
			if ($(this).attr('href').indexOf("?") != -1) { 
				qssp = '&'; 
			} else {
				qssp = '?';  
			}	
			if(jslang == 'TR') {
				$(this).attr('href', $(this).attr('href') + qssp + 'CategoryID=32978');
			} else {
				$(this).attr('href', $(this).attr('href') + qssp + 'CategoryID=35549');
			}
		});
	}
	/*if ($(".leftnews").length) { 
		if(jslang == 'TR') {
			$('.leftnews').load('/Haberler.htm .loadleftnews', function() {	});
		} else {
			$('.leftnews').load('/News.htm .loadleftnews', function() {	});
		}
	}*/
	
	//MENU ACTIVE
	if(location.pathname != "/") {
		$('.menu2 a[href^="' + location.pathname + '"]').addClass('active').parent().parent().prev().addClass('active');
		$('.menu1 a[href^="' + location.pathname + '"]').addClass('active');
		
		$('.leftnews a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
		$('.urunlink a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
	} else {
		$('.menu2 a:contains("Anasayfa")').addClass('active');
	}
	if($(".ANASAYFA").length) {
		$('.menu2 a:contains("Anasayfa")').addClass('active');
	}
	if($(".Home").length) {
		$('.menu2 a:contains("Home")').addClass('active');
	}
	/*$('.menu2 ul ul li:contains("• ")').addClass('submenu');
	$('.submenu').append('<ul></ul>');
	$('.submenu').nextUntil('.submenu').appendTo('.submenu ul');/*.addClass('subsubmenu')*/;
	//$('.submenu').css('color', 'red').wrapAll('<ul />');wrapInner,wrapAll,wrap,nextUntil
	//$('.submenu ~ .subsubmenu').nextUntil('.submenu').wrapAll('<ul />');*/
	
	if ($(".urunclass").length) {
		$('.urun0 a').addClass('active');
		//$('.urunlink a:contains("' + $(".urunclass").text() + '")').addClass('active');
		/*$('.urunlink a:contains("• ")').removeAttr('href').addClass('disable');
		$('.urunlink a:contains("• ")').text().replace('• ', '-');*/
		$(".urunlink a").each(function() {
			if ($(this).text() == $(".urunliste h1").text()) {
				$(this).addClass('active');
			}	
		});
	}

	//SORT
	comp('.yurtici');
	comp('.yurtdisi');
	comp('.belediyeler');
	
	//URUN SPECS EMPTYçöşiğü
	$(".spec:empty").parent().css('display', 'none');
	$("p:empty").remove();
	$(".listmb img:not([src*='images'])").parent().remove();

	//REFERANS ÜRÜN LİNK
	$(".refurunimg a").each(function() {
		if ($(this).text() == "-") {
			$(this).parent().remove();
		} else {
			$(this).prepend('<img src="/Images/urunler/' + $(this).text().replace(' ', '-') + '/S01.jpg?action=thumbnail&width=110&height=110">');
		}
	});

	//EBULTEN
	$('.hidsubs').hide();
	$('a.showsubs').click(function () {
		 $('.hidsubs').slideToggle();
		 return false;
	});
	
	$('.hidsubs input').click(function () {
		 $(this).val("");
	});
	
	//COLOR
	$("span.color").each(function() {
		arrr = $(this).text().split(", ");
		arrr[0]="white";
		arrr[1]="DarkGray";
		arrr[2]="black";
		arrr[3]="red";
		arrr[4]="green";
		arrr[5]="url(/Images/CSS/custcolor.png) no-repeat center center";
		for(var i = 0; i < arrr.length; i++) {
			 $('.arry').hide();
			 $(this).append("<img src='/Images/CSS/blank.gif' style='background:" + arrr[i] + "' alt='" +  arrr[i] + "'/ >");
		}
	});
	
	//REFCHECK
	//$('#CAT_Custom_139378').val('');
	$('.apptoform01').attr('checked', false);
	
   var radioChecked;
   $('.apptoform01').bind('mousedown', function() {
      radioChecked = $(this).attr('checked');
		//$(this).parent().css('color', '#C00');
   });
   $('.apptoform01').bind('click', function() {
      if (radioChecked) {
         $(this).attr('checked', false);
			$('#CAT_Custom_139378').val('');
         //$(this).parent().css('color', '#000');
      } else {
         $(this).attr('checked', true);
			$('#CAT_Custom_139378').val($(this).val());
			//$(this).parent().css('color', '#C00');
      }
   }); 
	
	//LOAD SWF
	if ($(".addSwf").length) { 
		var swfUrl = $(".addSwf").attr("href");
		$(".addSwf").parent().parent().parent().append('<iframe marginheight="0" marginwidth="0" frameborder="0" scrolling="no" src="'+swfUrl+'"></iframe>');
	}
	
	$(".refcategory").text($('.refcategory').text().replace('Anasayfa, ', ''));
	$(".refcategory").text($('.refcategory').text().replace('Referanslar, ', ''));
	$(".refcategory").text($('.refcategory').text().replace(', Referanslar', ''));
	
	
	
});

$(window).load(function() { 
	if ($(".refcategory").length) {
		$('.ref0 a:contains("' + $(".refcategory").text() + '")').addClass('active').parent().parent().prev().addClass('active');
	}
	$('.reflinks').append('<ul>'+$('.ref0 ul').html()+'</ul>');
	/*if($('.refcategory:contains("Yurtiçi")').length == 1 ) {
		$('.loadref').load('/Referanslar.htm .yurtici', function() { 
			comp('.yurtici');
			comp('.yurtdisi');
			comp('.belediyeler');
		} );
	}
	if($('.refcategory:contains("Yurtdışı")').length == 1 ) {
		$('.loadref').load('/Referanslar.htm .yurtdisi', function() { 
			comp('.yurtici');
			comp('.yurtdisi');
			comp('.belediyeler');
		} );
	}
	if($('.refcategory:contains("Belediyeler")').length == 1 ) {
		$('.loadref').load('/Referanslar.htm .belediyeler', function() { 
			comp('.yurtici');
			comp('.yurtdisi');
			comp('.belediyeler');
		} );
	}*/
	if($('.refcategory:contains("Yurtiçi")').length == 1 ) {
		$('.loadref').load('/Yurtici.htm .yurtici', function() { 
			comp('.yurtici');
		} );
	}
	if($('.refcategory:contains("Yurtdışı")').length == 1 ) {
		$('.loadref').load('/Yurtdisi.htm .yurtdisi', function() { 
			comp('.yurtdisi');
		} );
	}
	if($('.refcategory:contains("Belediyeler")').length == 1 ) {
		$('.loadref').load('/Belediyeler.htm .belediyeler', function() { 
			comp('.belediyeler');
		} );
	}
});

//FUNCTIONS
function comp(ulname) {
	$(".reffull a:contains('-')").each(function(i) {
		var compname = $(this).text().split('-');
		if (compname.length > 2) $(this).html("<strong class='compname'>" + compname[0] + "<br /></strong>" + compname[1] + " / <em>" + compname[2] + "</em>");
		else $(this).html("<strong class='compname'>" + compname[0] + "<br /></strong><em>" + compname[1] + "</em>");
	});
	
	var a = new Array();
	$(ulname + ' .compname').each(function(x) {
	//$('.reffull .compname').each(function(x) {
		test = false;
		b = a[x] = $(this).text();
		for (i=0;i<a.length-1;i++){
			if (b ==a[i]) test =true;
		}
		if (test) $(this).remove();
	});
	
	$(".refall p:not([title*='images']) a").css('color', '#999');
	$(".refall p:not([title*='images']) a").removeAttr('href');
	
}

