// Bind the possible Add to Cart btns with event to position top links
$(document).ready(function(){
	
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
        $("#pnlRevolutionSlider").hide();
        $("#pnlFlexSlider").show();
    }
    else {
        $("#pnlRevolutionSlider").show();
        $("#pnlFlexSlider").hide();
    }

    $("#form1").validationEngine('attach', { promptPosition: "topLeft", scroll: false });

    $('#tabs a').tabs();

    $('.jqzoom').jqzoom({
        zoomType: 'standard',
        lens: true,
        preloadImages: false,
        alwaysOn: false
    });

    //hızlı menü
    $('.slide-out-div').tabSlideOut({
        tabHandle: '.handle',                     //class of the element that will become your tab
        //path to the image for the tab //Optionally can be set using css,
        //width of tab image            //Optionally can be set using css
        tabLocation: 'right',                      //side of screen where tab lives, top, right, bottom, or left
        speed: 300,                               //speed of animation
        action: 'click',                          //options: 'click' or 'hover', action to trigger animation
        topPos: '200px',                          //position from the top/ use if tabLocation is left or right
        leftPos: '20px',                          //position from left/ use if tabLocation is bottom or top
        fixedPosition: false                      //options: true makes it stick(fixed position) on scroll
    });
    $('.hizlimenubg').hover(function () {
        $('.hizlibaslik').text($(this).attr('rel'));
    })

    //homepage slider
    $('.sliderlink').click(function () {
        var href = $(this).data('href');
        var target = $(this).data('target');
        if (href != "") {
            //alert(target);
            if (target == "_top") {
                window.location = href;
            } else {
                window.open(href);
            }
        }
    })


    //homepageslider
    var revapi2;
    if ($.fn.cssOriginal != undefined)
        $.fn.css = $.fn.cssOriginal;

    if ($('#rev_slider_2_1').revolution == undefined)
        revslider_showDoubleJqueryError('#rev_slider_2_1');
    else
        revapi2 = $('#rev_slider_2_1').show().revolution(
        {
            delay: 6000,
            startwidth: 940,
            startheight: 450,
            hideThumbs: 200,

            thumbWidth: 100,
            thumbHeight: 50,
            thumbAmount: 4,

            navigationType: "none",
            navigationArrows: "bullet",
            navigationStyle: "round",

            touchenabled: "on",
            onHoverStop: "on",

            navOffsetHorizontal: 0,
            navOffsetVertical: 20,

            shadow: 0,
            fullWidth: "on",

            stopLoop: "off",
            stopAfterLoops: -1,
            stopAtSlide: -1,

            shuffle: "off",

            hideSliderAtLimit: 0,
            hideCaptionAtLimit: 0,
            hideAllCaptionAtLilmit: 0
        });

    var sondeger = 0;
    setInterval(function () { resize(); }, 1000);
    function resize() {
        if ($(window).width() != sondeger) {
            sliderss();
            if (sondeger == 0) {
                rotateSwitch();
            };
            sondeger = $(window).width();
        }
    };

	// Menu Animation
    $('#menu ul li').hover(
        function() {
            $(this).addClass("active");
            $(this).find('div').not('.subsub_menu, .subsubsub_menu').stop(false, true).slideDown({
            	duration:300,
            	easing:"easeOutExpo"});
        },
        function() {
            $(this).removeClass("active");        
            $(this).find('div').not('.subsub_menu, .subsubsub_menu').stop(false, true).slideUp({
            	duration:100,
            	easing:"easeOutExpo"});
        }
    );

	// Sub Menu Animation
    $('#menu ul li li').hover(
        function() {
            $(this).find('.subsub_menu').stop(false, true).slideDown({
            	duration:300,
            	easing:"easeOutExpo"});
        },
        function() {        
            $(this).find('.subsub_menu').stop(false, true).hide();
        }
    );	
    
    // Subsub Menu Animation
    $('#menu ul li li li').hover(
    		function() {
    			$(this).find('.subsubsub_menu').stop(false, true).slideDown({
    				duration:300,
    				easing:"easeOutExpo"});
    		},
    		function() {        
    			$(this).find('.subsubsub_menu').stop(false, true).hide();
    		}
    );	
	

	
	// Sidebar Nav effects	
	$('.side_bar_nav a').not(".active").hover(
		function() {
			$(this).children('.hover_span').stop().animate({width:'100%'},500,'easeOutExpo');
		},
		function() {
			$(this).children('.hover_span').stop().animate({width:'0'},200,'easeOutExpo');
		}
	);	

	
	
	/* Accordions */	
	accordion = true;

	$(".acc_item").click(function(){
		
		if(accordion){
			$(".accordion_content").not($(this).find(".accordion_content")).slideUp(600,'easeInOutExpo');
			$(".accordion").not($(this).find(".accordion")).removeClass("active_acc");
		}
		$(this).find(".accordion").next(".accordion_content").slideToggle(600,'easeInOutExpo');
		
		if($(this).find(".accordion").hasClass('active_acc')){
			$(this).find(".accordion").removeClass("active_acc");
		}else{
			$(this).find(".accordion").addClass("active_acc");
		}
	});
	
	// Open First item if accordion is set to true;
	if(accordion){
		setTimeout(function(){$(".acc_holder .acc_item:first-child .accordion").delay(1500).click();},600);
	}	
	/* Accordions::END */
	
	
	
	/* Info Messages */
	$(".closable").each(function(){
		$(this).prepend('<a class="close_img"></a>');		
	});
	
	$(".close_img").click(function(){
		$(this).parent().fadeOut(600);
	});
	

	// Sidebar Menu effects
	$('.side_bar_menu a').not(".active").hover(
			function() {
				$(this).children('.hover_span').stop().animate({width:'100%'},500,'easeOutExpo');
			},
			function() {
				$(this).children('.hover_span').stop().animate({width:'0'},200,'easeOutExpo');
			}
	);	
	
	
});

/* TABS */
$.fn.tabs = function() {
	var selector = this;
	
	this.each(function() {
		var obj = $(this); 
		
		$(obj.attr('href')).hide();
		
		$(obj).click(function() {
			$(selector).removeClass('selected');
			
			$(selector).each(function(i, element) {
				$($(element).attr('href')).hide();
			});
			
			$(this).addClass('selected');
			
			$($(this).attr('href')).fadeIn();
			
			return false;
		});
	});

	$(this).show();
	
	$(this).first().click();
};

var enbuyuk = 0;

$(window).load(function () {
    $('.flexslider').flexslider({
        animation: "slide",
        /*startAt: 1,*/
        start: function (slider) {
            $('body').removeClass('loading');
        }
    });
    setTimeout(function () {

        $('.flex-caption').each(function (e) {

            if ($(this).height() > enbuyuk) {
                enbuyuk = $(this).height();
                $('.flex-caption').css('min-height', enbuyuk);
                console.log(enbuyuk);
            }
        });
    }, 500);
});