$(document).ready(function() {
  /*  
    var galleries = $(".mygallery").myGallery({width:470});
    $('#switch-effect').change(function() {
        galleries[0].settings.effect = $(this).val();
        return false;
    });
    //$("#manset-mygallery-tab0").css('height', mh+'px');
    //$("#manset_mygallery_tab_button0").attr('class', 'act');
        
  */  

    jQuery("#main_slider").nivoSlider({
        width:475,
        height:320,
        effect:"fade",
        slices:15,
        boxCols:8,
        boxRows:4,
        animSpeed:100,
        pauseTime:8000,
        startSlide:0,
        directionNav:true,
        directionNavHide:true,
        controlNav:true,
        controlNavThumbs:false,
        controlNavThumbsFromRel:true,
        keyboardNav:false,
        pauseOnHover:true,
        manualAdvance:false
    });
    
    $(".zebra tr:even").addClass ("ikinci");
    $("#Firsatlar-2").easySlider({ 
            auto: true,
            continuous: true,
            prevId: 'OncekiBtn_mini',
            prevText: '',
            nextId: 'SonrakiBtn_mini',	
            nextText: '',
            speed: 	300,
            pause:	3000
    });
    $('#slideicerik, #Firsatlar,#Firsatlar-2').css('visibility','visible');
    $("#tab li").click (function() {
            $('#tab li').removeClass ("item_active");
            $(this).addClass ("item_active");
    });

    $(".tab_content").hide();
    $("ul.tabs li:first").addClass("active").show();
    $(".tab_content:first").show();
    $("ul.tabs li").click(function() {
        $("ul.tabs li").each(function(){
            $(this).removeClass("active").attr('style',$(this).attr('rel'));
        });
        $(this).addClass("active").removeAttr('style');
        $(".tab_content").hide();
        var activeTab = $(this).find("a").attr("href"); 
        $(activeTab).fadeIn();
        return false;
    });
        
    $('#firsat1 a,#firsat2 a').each(function(){
        var id = $(this).attr('rel');
        var iz = $(this).parent().attr('id') ;
        var aid = iz.substr((iz.length)-1);
        var clr = (aid == 1) ? 'blue' : 'magenta' ;
        $(this).addClass('awesome button '+clr+' large').removeAttr('href').click(function(){
            ajaxcagri('sr='+id,'otelfirsat'+aid);
            aktifle(this);
        });
    }); 
    $('#firsat1 a:first,#firsat2 a:first').click();
    $('#footer_menu span a').addClass('awesome button magenta medium') ;
    $('#arama_alani').attr('style','display:block; visibility: visible; width:460px; height:200px; margin-right:5px; float:left; margin-bottom:10px;');
    $('#UcakGidisTarih,#UcakDonusTarih,#OtelGirisTarih,#OtelCikisTarih,#AracAlisTarih,#AracTeslimTarih').datepicker({dateFormat: 'dd/mm/yy'});		
    $("#UcakNereden,#UcakNereye,#YurtdisiOtelSehir,#AracAlisSehir").autocomplete('/cities.php', {
    selectFirst: true,
    width: 150,
    limit:10,
    formatItem: function(data, i, n, value) {
        var e =  data ; 
        return e[0] + '<br /><span style="font-size:10px;">'+ e[1] + '</span>';
    }
    }).result(function(event, data, formatted) { 
        $(this).val(data[0]+' / '+data[1]); 
        var alt = '#'+$(this).attr('rel');
        $(alt).val(data[2]);
    });
    

    
    $('img.menu_class').click(function () {
        if ($(this).attr('src') == '/images/canlidestek.png') {
            $('#header_bottom').slideDown();
        }
        else { 
           $('#header_bottom').slideUp();
        } 
    });
});
function aktifle(id) {
    $(id).parent().children('a').removeClass('aktif');
    $(id).addClass('aktif');
}

function ajaxcagri(datas,div) {
    $(function () {
        jQuery.ajax({   
            beforeSend: function(){$('#'+div).html('<br /><br /><br /><div align="center"><img src="/images/yukleniyor.gif" /><br /><span style="font-siz:14px; color:#06c; font-weight:bold;">Yükleniyor.<br />Lütfen Bekleyiniz...</span></div>');},
            type: 'GET',
            url: 'index_kampny.php',
            data: ''+datas,   
            error:function(){$('#'+div).html("Lütfen tekrar deneyiniz.");},
            success: function(veri) { 
                $('#'+div).html(veri);
                $('#'+div+' .infiniteCarousel').infiniteCarousel();
            }   
        }); 
    });
}


function checkFlightType(type) {
    if (type=='OneWay') {
        $('#UcakDonusTarih').val('').css('visibility','hidden').parent('td').previous().text('');
    }
    else if (type=='RoundTrip') {
        $('#UcakDonusTarih').css('visibility','visible').datepicker({dateFormat: 'dd/mm/yy'}).parent('td').previous().text('Dönüş Tarihi');
    }
}

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
    
    
    
};
/*
function showmytab(num) {
    for (var mi = 0; mi < manset_mygallery_tabs.length; mi++) {
        if (mi == num) {
            $("#manset-mygallery-tab"+mi).css('height', mh+'px');
            $("#manset_mygallery_tab_button"+mi).attr('class', 'act');
        } else {
            $("#manset-mygallery-tab"+mi).css('height', 0+'px');
            $("#manset_mygallery_tab_button"+mi).attr('class', 'nor');
        }
    }
}

var manset_mygallery_tabs = new Array();
var mh = 260 + 65;
                
*/

    
