var crtDiv = 1;

/*jQuery(document).ready(function() {
	var $tabs = jQuery("#tabs").tabs({ fx: { opacity: 'toggle' } });
	jQuery('.oferte_prima_pag').css('display', 'none');
	jQuery('.oferte_prima_pag').width(jQuery('.noutati').width());
	jQuery('.oferte_prima_pag').css('display', 'block');
	$tabs.tabs('select', tip - 1);
    jQuery('#tabs').bind('tabsselect', function(event, ui) {
        jQuery('#tabs>ul>li').each(function(index, domElement) {
            jQuery('#tabs>ul>li:nth-child(' + (index + 1) + ')').removeClass('sel_mijloc');
            jQuery('#tabs>ul>li:nth-child(' + (index + 1) + ')').addClass('back_mijloc');
        });
        
        jQuery('#tabs>ul>li:nth-child(' + (ui.index + 1) + ')').removeClass('back_mijloc');
        jQuery('#tabs>ul>li:nth-child(' + (ui.index + 1) + ')').addClass('sel_mijloc');
        
        tip = ui.index + 1;
        crtDiv = 1;

}); 
	
	jQuery('.changeTab').click(function(e) {
		var indexDash = jQuery(this).attr('href').indexOf('=') + 1;
		var selTab = jQuery(this).attr('href').substring(indexDash);
		$tabs.tabs('select', selTab);
	});
    
    jQuery(document).everyTime(5000, function(i) {
        moveRight();
		var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
		
        jQuery("#crt_oferta" + type).html("<div class=\"loader\"><img src=\""+ absPath + "imagini/loader.gif\" /><br />Se incarca...</div>");
		
        jQuery("#crt_oferta" + type).load("oferta.php?id=" + crtDiv + "&tip=" + type, function() {
            jQuery("#crt_oferta" + type).css("opacity","0.1"); 
            jQuery("#crt_oferta" + type).fadeTo("slow", 1);
        });
    });
    
    jQuery(".slider_left").click(function(e) {
        moveLeft();
		
		var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
        
		jQuery("#crt_oferta" + type).html("<div class=\"loader\"><img src=\""+ absPath + "imagini/loader.gif\" /><br />Se incarca...</div>");
		
        jQuery("#crt_oferta" + type).load("oferta.php?id=" + crtDiv + "&tip=" + type, function() {
            jQuery("#crt_oferta" + type).css("opacity","0.1"); 
            jQuery("#crt_oferta" + type).fadeTo("slow", 1);
        });
    });
    
    jQuery(".slider_right").click(function(e) {
        moveRight();
		
		var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
		
        jQuery("#crt_oferta" + type).html("<div class=\"loader\"><img src=\""+ absPath + "imagini/loader.gif\" /><br />Se incarca...</div>");
        jQuery("#crt_oferta" + type).load("oferta.php?id=" + crtDiv + "&tip=" + type, function() {
            jQuery("#crt_oferta" + type).css("opacity","0.1"); 
            jQuery("#crt_oferta" + type).fadeTo("slow", 1);
        });
    });
    
    jQuery(".detalii_sec").click(function(e) {
	var id = jQuery(this).parent().attr("id").replace(/oferta/, "");
	id = id.replace(/_[0-9]/, "");
        changeCrt(id);
    });	
}); */

function moveLeft() {
    // If we have reached the end, return to start
    if (crtDiv <= 1) {
        crtDiv = 1;
        return;
    }
	
	var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
    
    var crtScroll = 0;
    for (var i = 1; i < crtDiv - 1; i++) {
        crtScroll += jQuery("#oferta" + crtDiv + "_" + type).outerWidth(true) + (jQuery.browser.mozilla ? 4 : 0);
    }
    
    // Urmatoarea proprietate
    jQuery("#oferte_mici" + "_" + type).animate({
        scrollLeft : crtScroll
    }, 1000 );
    
    crtDiv--;
}

function moveRight() {
	var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
	
    // If we have reached the end, return to start
    if (jQuery("#oferta" + (crtDiv + 1) + "_" + type).size() == 0) {
        crtDiv = 1;
        jQuery("#oferte_mici" + "_" + type).animate({
            scrollLeft : 0
        }, 1000 );
        return;
    }
    
    var crtScroll = 0;
    for (var i = 1; i < crtDiv; i++) {
        crtScroll += jQuery("#oferta" + crtDiv + "_" + type).outerWidth(true) + (jQuery.browser.mozilla ? 4 : 0);
    }
    
    var nextDivWidth = jQuery("#oferta" + crtDiv + "_" + type).outerWidth(true) + (jQuery.browser.mozilla ? 4 : 0);
    
    // Urmatoarea proprietate
    jQuery("#oferte_mici" + "_" + type).animate({
        scrollLeft : crtScroll + nextDivWidth
    }, 1000 );
    
    crtDiv++;
}

function setVisible() {
	var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
	
    jQuery('#oferte_mici_' + type + '>li').each(function(index, domElement) {
        jQuery('#oferte_mici_' + type + '>li:nth-child(' + index + ')').addClass('hidden');
    });
    
    var total = jQuery('#oferte_mici_' + type + '>li').size();
    
    jQuery('#oferte_mici_' + type + '>li').each(function(index, domElement) {
        if (index >= crtDiv && index <= crtDiv + 3)
            jQuery('#oferte_mici_' + type + '>li:nth-child(' + index + ')').removeClass('hidden');
        // if (index >= crtDiv && index <= crtDiv + 3)
    });
}

function changeCrt(id) {
	var type = jQuery('#tabs>ul>li:nth-child(' + tip + ')').children(":first-child").attr("href").replace(/#tabs-/, '');
	
    jQuery("#crt_oferta" + type).html("<div class=\"loader\"><img src=\""+ absPath + "imagini/loader.gif\" /><br />Se incarca...</div>");
    jQuery("#crt_oferta" + tip).load("oferta.php?id=" + id + "&tip=" + type, function() {
            jQuery("#crt_oferta" + type).css("opacity","0.1"); 
            jQuery("#crt_oferta" + type).fadeTo("slow", 1);
    });
}
