// Javascript document
//http://blog.magenta-advertising.ro/index.php?cat=32&feed=rss2
currentSlide = 0;
slideDuration = 5000;
slideWidth = 750;

jQuery.noConflict();
(function($) { 
  $(function() {
    $(document).ready(function () {
        
        

            $.ajax({
    		type: "GET",
    		url: feedURL,
    		dataType: "xml",
    		success: function(xml) {
    		    blogContainer = $('#rssBlog');
    		    blogTemplate = $('#rssBlog').find('.blogFeedTemplate');
    			$(xml).find('item:lt(3)').each(function(){
    			    item = $(this);
    			    bTitle = item.find('title').text();
    			    bDesc = item.find('description').text();
    			    bLink = item.find('link').text();
    			    blogTemplate.clone(true).removeClass("hidden").
    			                find(".bTitle a").html(bTitle).attr("href", bLink).end().
    			                find(".bDesc").html(bDesc).end().
    			                find(".bLink a").attr("href", bLink).end().
    			                appendTo(blogContainer);
    	
    			});
    		}
    	});
            
        
        
        //Right hidden Bar show and hide --------------------------
		controlHoldingDivOriginalHtml  = $('#controlHiddenRightContent').html();
		$('#controlHiddenRightContent').click(function () {
			holdingDiv = $('#hiddenRightBar');
			if (holdingDiv.css('display') == 'none') {
				holdingDiv.slideDown();
				$(this).html('ascunde');
				$('#logo').animate({
				    "margin-left" : "0px"
				});
				$('#quercusholder').slideDown();
			} else  {
				holdingDiv.slideUp();
				$(this).html(controlHoldingDivOriginalHtml);	
				$('#logo').animate({
				    "margin-left" : "25px"
				});
				$('#quercusholder').slideUp();
			}
			return false;
		});
		//-------------
        
		
		
		//Gwwzial --------------------------
        gwCurrentSlot = 0;
		gwTotalSlots = $('.gwSlotContainer .gwSlot').length;
		gwSlotHeight = parseInt($('.gwSlotContainer .gwSlot').css('height'),10);
		gwTimer = 5 * 1000;
		gwID = setTimeout(nextSlot, gwTimer);
		
		$('#gwController a').click(function (){
			 gwMyDest = $('#gwController a').index(this);
			 gotoGwSlot(gwMyDest);
			 //$(this).addClass('sel').parent().siblings().find('a').removeClass('sel');
			 return false;
		});
        
		function nextSlot (){
			gotoGwSlot(gwCurrentSlot + 1);
		}
		
		function gotoGwSlot (dest) {
			if (dest>=gwTotalSlots) dest = 0;
			$('#gwController a').removeClass('sel').eq(dest).addClass('sel');
			$('.gwSlotContainer').animate({
				'top':(-dest*gwSlotHeight)+'px'
			});
			
			$('#gwController').css ({'background-position' : '0px '+ 100*dest + 'px'	});
			gwCurrentSlot = dest;
			clearTimeout (gwID);
			gwID = setTimeout(nextSlot, gwTimer);
		}
		//-------------
        


        //Capturi --------------------------
        cpCurrentSlot = 0;
		cpTotalSlots = $('#capturi img').length;
		cpSlotHeight = parseInt($('#capturi img').css('height'),10);
		cpTimer = 5 * 1000;
		cpID = setTimeout(nextcpSlot, cpTimer);
		
		$('#capturiControls a').click(function (){
			 gwMyDest = $('#capturiControls a').index(this);
			 gotocpSlot(gwMyDest);
			 //$(this).addClass('sel').parent().siblings().find('a').removeClass('sel');
			 return false;
		});

		function nextcpSlot (){
			gotocpSlot(cpCurrentSlot + 1);
		}
		
		$("#detailPic a").click(function () {

           nextcpSlot();
            return false;
        });
		
		function gotocpSlot (dest) {
			if (dest>=cpTotalSlots) dest = 0;
			$('#capturiControls a').removeClass('sel').eq(dest).addClass('sel');
			$('#capturi').animate({
				'top':(-dest*cpSlotHeight)+'px'
			});
			cpCurrentSlot = dest;
			clearTimeout (cpID);
			cpID = setTimeout(nextcpSlot, cpTimer);
		}
		//-------------

		// Slider Noutati Produse ------------------------------
		scrollStep = 250;
		rArr = $("#controlsContainer .rarr");
		lArr = $("#controlsContainer .larr");
		
		slideWidth = $("#controlsContainer #capturiControls").height();
		viewportWidth = $("#controlsContainer #controlsViewport").height();
		slidePos = parseInt($('#capturiControls').css("top"));
		rArr.click(function () {
			slidePos = parseInt($('#capturiControls').css("top"));
			//console.log(slideWidth);
			if ((slideWidth+slidePos - viewportWidth) > scrollStep) {
				destination = slidePos - scrollStep;
			} else {
				destination = -slideWidth + viewportWidth;
			}
			$('#capturiControls').animate({
				"top":destination+"px"
			});
			return false;
		});
		lArr.click(function () {
			slidePos = parseInt($('#capturiControls').css("top"));
			if (slidePos < 0) {
				if (slidePos < -scrollStep) {
					destination = slidePos + scrollStep;
				} else {
					destination = 0;
				}
				$('#capturiControls').animate({
					"top":destination+"px"
				});
			}
			return false;
		}); 



		
    });
    





});
})(jQuery);



