$(function() {
	//	data picker
	$("input.date_picker").datepicker({minDate: '-98Y', maxDate: '-18Y-1D', dateFormat: 'yy-mm-dd', regional: 'ro', changeMonth: true , changeYear: true,dayNamesMin: ['Du', 'Lu', 'Ma', 'Mi', 'Jo', 'Vi', 'Sa'],firstDay: 1,monthNamesShort: ['Ian','Feb','Mar','Apr','Mai','Iun','Iul','Aug','Sep','Oct','Nov','Dec'],navigationAsDateFormat: true ,yearRange: '1960:2009'   });
	//	address
	$("select.addr_county_id").change(function(){
		county_id=$("select.addr_county_id").val();
		//alert('county_id: ' + county_id);
		if(county_id>0)
	    {
	    	$('select.addr_locality_id').load('/get/localities/', {'county_id': county_id, 'frm_name': ''});
	    }
	    else
	    {
	    	$('select.addr_locality_id').html('<option value="">alege</option>');
	    }
	});
	//	vote form
	//${'#btn_vote_show'}.hide();
	/*
	${'#btn_vote_show'}.bind(
		"click",
        function() {
			${'form#frm_vote'}.show();
        }
	);
	*/
	/*

	frm_vote_posted=${'input#frm_vote_posted'}.val();
	if(frm_vote_posted=1)
	{
		alert(frm_vote_posted);
	}
	else
	{
		alert(frm_vote_posted);
		${'form#frm_vote'}.hide();
	}
	*/
     $('a#share_this_hi5').bind("click", function(){
        $('#frm_share').fadeIn(); 
        return false;     
     });  
     
     if($('#frm_login div').hasClass('error')){
      $('div.login-err-msg').show();
      toggleLogin();
      }
     
     $('.boxy-announcement a').click(function() {
            Boxy.alert("<p>Dragi vizitatori,<p><br><p>Pentru a ne asigura că regulamentul concursului este respectat, echipa tehnică verifică în permanenţă funcţionalităţile website-ului. Astfel, s-a descoperit faptul că, în pagina de profil a participanţilor înscrişi în timpul primei săptămâni de concurs, s-a afişat şi locul pe care aceştia îl ocupă în topul celei de-a 2-a săptămâni de concurs. Conform regulilor de desfăşurare a concursului, topul săptămânal poate fi afişat doar pentru pozele înscrise în concurs în timpul săptămânii respective (în acest caz, fotografiile înscrise în concurs în prima săptămână nu ar fi trebuit să aibă disponibil în pagina de profil şi topul celei de-a doua săptămâni).</p><br><p>Eroarea respectivă a fost corectată.</p><br><p>Mulţumim celor dintre dumneavoastră care au observat şi ne-au adus la cunoştinţă aceste probleme şi ne cerem scuze pentru eventualele neplăceri create.</p><br><p>Vă urăm succes şi va invităm la de zece ori mai multă distracţie!</p><br><br><p>Mulţumim,</p><p>Echipa Duracell</p>",null,{closeText: 'X'});
            return false;
     });
});
 
function toggleLogin() {
    $('#frm_login').slideDown('fast');
    $('#frm_login_user').focus();
    return false;
}

function toggleVote() {
    if($('#frm_send_to_a_friend').is(':visible')) $('#frm_send_to_a_friend').hide();
    $('#frm_vote').fadeIn();
    return false;
}
function toggleFriend() {
    if($('#frm_vote').is(':visible')) $('#frm_vote').hide();
    $('#frm_send_to_a_friend').fadeIn('fast');
    return false;
}
function enableNext() {
    //alert('mere');
    //$('#frm_add_picture_submit_apply').removeAttr('enabled').focus();
    $('#frm_add_picture_submit_apply').fadeIn().focus();
}
     /*
  jQuery.fn.liScroll = function(settings) {
        settings = jQuery.extend({
            travelocity: 0.07
        }, settings);        
        return this.each(function(){
                var $strip = jQuery(this);
                $strip.addClass("newsticker")
                var stripWidth = 0;
                var $mask = $strip.wrap("<div class='mask'></div>");
                var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");                                
                var containerWidth = $strip.parent().parent().width();    //a.k.a. 'mask' width     
                $strip.find("li").each(function(i){
                stripWidth += jQuery(this, i).width();
                });
                $strip.width(stripWidth);            
                //var defTiming = stripWidth/settings.travelocity;
                //console.log(defTiming);
                //var totalTravel = stripWidth+containerWidth;                                
                
                var totalTravel = stripWidth+containerWidth;
                var defTiming = totalTravel/settings.travelocity;
                function scrollnews(spazio, tempo){
                $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
                }
                scrollnews(totalTravel, defTiming);                
                $strip.hover(function(){
                jQuery(this).stop();
                },
                function(){
                var offset = jQuery(this).offset();
                var residualSpace = offset.left + stripWidth;
                var residualTime = residualSpace/settings.travelocity;
                scrollnews(residualSpace, residualTime);
                });            
        });    
};

$(function(){ 
     $("body.homepage ul.gallery").liScroll({travelocity: 0.06}); 
}); */


(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,
        pauseOnHover: false,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible, paused=0;
        
        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }
        
        // Set pause flag
        o.pauseOnHover ? ul.hover(function (){paused=1}, function (){paused=0}) : "";
        
        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", 'float': o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running && !paused) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
};

function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};

})(jQuery)
$(function() {
    $("body.homepage div.contest_pictures").jCarouselLite({
        auto: 1000,
        speed: 2000,
        scroll:1,
        pauseOnHover: true
    });

});