$(document).ready(function() {

	// mobitel detaljno - drop-down za tarife - privatni
	
	var poslovni12 = $("#poslovni-ugovor-12");
	var poslovni24 = $("#poslovni-ugovor-24");
	
	$(".price-table-options-holder select#choose-contract-type-poslovni").change(function() { 
		if ($(this).val() != 0) {
			openDevicePriceTablePoslovni($(this).val());
		}
	});
	
	function openDevicePriceTablePoslovni (contract) {
		hideDevicePriceTablesPoslovni();
		if (contract == "1"){
			poslovni12.fadeIn(700); 
		}
		else if (contract == "2"){
			poslovni24.fadeIn(700); 
		}
	}
	
	function hideDevicePriceTablesPoslovni () {
		poslovni12.hide();
		poslovni24.hide();
	}
	
	
	// mobitel detaljno - drop-down za tarife - privatni
	
	var customerType = 1;
	var contractType = 2;

	var novi12 = $("#novi-ugovor-12");  
	var novi24 = $("#novi-ugovor-24");
	var postojeci12 = $("#postojeci-ugovor-12");
	var postojeci24 = $("#postojeci-ugovor-24");
	
	$(".price-table-options-holder select#choose-customer-type").change(function() { 
		if ($(this).val() != 0) {			
			customerType = $(this).val();
			openDevicePriceTable(customerType,contractType);
		}
	});
	$(".price-table-options-holder select#choose-contract-type").change(function() { 
		if ($(this).val() != 0) {
			contractType = $(this).val();
			openDevicePriceTable(customerType,contractType);
		}
	});
	
	
	
	function openDevicePriceTable(customer,contract){
		hideDevicePriceTables();
		if (customer == "1" && contract == "1"){
			novi12.fadeIn(700); 
		}
		else if (customer == "1" && contract == "2"){
			novi24.fadeIn(700); 
		}
		else if (customer == "2" && contract == "1"){
			postojeci12.fadeIn(700); 
		}
		else if (customer == "2" && contract == "2"){
			postojeci24.fadeIn(700); 
		};
	}
	
	function hideDevicePriceTables() {
		novi12.hide();
		novi24.hide();
		postojeci12.hide();
		postojeci24.hide();
	}
		
	
	// search box click
	var searchBoxField = $('.search-textfield-down');
	var searchBoxFieldDefault = "Pretraži";	
	searchBoxField.focus(function(){
		if($(this).attr("value") == searchBoxFieldDefault) $(this).attr("value", "");
		$(this).addClass("active");
	});
	searchBoxField.blur(function(e){ 
		if($(this).attr("value") == "") $(this).attr("value", searchBoxFieldDefault);
		$(this).removeClass("active");
	});


    // FLASH EMBED
    $('body.home .index-lvl-2.1497').flash({ swf: '/assets/swf/home/privatni/eronet_flash_kontejner_privatni.swf', height: 220, width: 940 });
    $('body.home .index-lvl-2.1498').flash({ swf: '/assets/swf/home/poslovni/eronet_flash_kontejner_poslovni.swf', height: 220, width: 940 });

    $("a.mail-this-page").fancybox({
        'hideOnContentClick': false,
        'overlayShow': true,
        'frameWidth' : 470, 
        'frameHeight' : 500
    });

    $("a.device-gallery").fancybox({
        'overlayShow' : true,
        'zoomSpeedIn' : 600,
        'zoomSpeedOut' : 500,
        'easingIn' : 'easeOutBack',
        'easingOut' : 'easeInBack'
    });

    // HOME - device slider
    $(".devices-items").jCarouselLite({
        btnNext: "#devices-next",
		btnPrev: "#devices-prev",
        visible: 3,
        auto: 3000,
        speed: 500,
		hoverPause: true,
		vertical: true
    });
	
	// HOME - device slider - hover event
    $(".devices-items li").hover(
      function () {
		$(this).find(".device-image").addClass("active");
		$(this).find(".device-text").show();
		//$(this).parent().css("overflow","auto").css("z-index","500");
      }, 
      function () {
		$(this).find(".device-image").removeClass("active");
		$(this).find(".device-text").hide();
      }
    );


    // MOBITEL-DETALJNO - tabovi
    $("#table.feature-tabs").tabs({ event: 'click', selected: 0, fx: { opacity: 'toggle', duration: 'fast'} });

    // MOBITEL-DETALJNO - zebra table
    $(".table table").each(function() {
        $("tr:odd", this).not(".even").addClass("odd");
        $("tr:even", this).not(".odd").addClass("even");
    });

    // SELECT/OPTION trigger
    $(".index-banner-holder select, select.select-box").change(function() { 
		if ($(this).val() != 0) location.href = $(this).val(); 
	});
	
	$(".tb-wrap a").attr( "href", $(".tb-wrap select").val() );
	

    // FAQ accordion
//    $('.faq-list').accordion({ navigation: true, autoHeight: false, active: false, header: 'h2', alwaysOpen: false,
//	    change: function(e,data){if (data.newHeader.length>0) $('html,body').animate({scrollTop: data.newHeader.offset().top}, 500);}
//	});

	// FAQ accordion
	$('.faq-list').accordion({ header: 'h2', autoHeight: false, alwaysOpen: false, navigation: true, collapsible: true, active: false });


    // add an 'esc' key handler for jqModals
    $(document).keydown(function(e) {
        if (e.which == 27) {
            // escape, close box
            $('.jqmWindow').jqmHide();
        }
    });
    

    // Reset Font Size
    var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function() {
        $('.content-wide').css('font-size', originalFontSize);
    });
    // Increase Font Size
    $(".text-bigger").click(function() {
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 1.2;
        $('.content-wide').css('font-size', newFontSize);
        return false;
    });
    // Decrease Font Size
    $(".text-smaller").click(function() {
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum * 0.8;
        $('.content-wide').css('font-size', newFontSize);
        return false;
    });
    
    $('#features').jshowoff({controls:false, speed:10000, hoverPause:false});


});