/**
 * We use the initCallback callback
 * to assign functionality to the controls
 */
function mycarousel_initCallback(carousel) {
    jQuery('#jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
	// Disable autoscrolling if the user clicks the prev or next button.
    jQuery('#jcarousel-control a').bind('click', function() {
        carousel.startAuto(0);
    });
 
   jQuery('#jcarousel-control a').bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    jQuery('#jcarousel-control a').hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
 
   
};
 
// Ride the carousel...



// JavaScript Document
$(document).ready(function(){
						   
// Pentru slider de pe prima pagina
						   
		$('a.cumpara').click(function(e){
									  var sku = $(this).attr('title');
									  var el = $(this);
									  $.ajax({type: "POST",url: "http://www.echipamentmilitar.ro/functions/addtobasket.php",data: "sku="+sku,success: function(msg){
											if(msg!='Eroare!') {
     											
												var posx = e.pageX;
												var posy = e.pageY;
												el.parent().append('<span class="plusone" style="left:'+posx+'px; top:'+posy+'px;">Adaugat in cos!</span>').fadeIn("slow",function(){
												
												var el2 = $('a.cos_prod').position();												
												$("span.plusone").attr("position","absolute").animate({left:el2.left,top:el2.top},2000,function(){ 
																																				
																							$('a.cos_prod').css('color','#FDCE40').css('font-weight','bold').html(msg);
																																				$(this).fadeOut("slow");});
																																		  
												});
											}
  											 }
									  });
									  return false;
									  });				   
		$("#msg").hide();
		$('.numeric').numeric();
		$('.alfanumeric').alphanumeric();
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li span").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	$("ul.topnav li a.topm").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").hide(); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	
	$("#accordion").accordion({ autoHeight: false},{ navigation: true },{navigationFilter: function () {

		var sidebarURL = this.href;
		var currentURL = location.href;
		var temp = currentURL.split('/');
		var computedURL = temp[0] + '/' + temp[1] + '/' + temp[2] + '/' + temp[3] + '/' + temp[4];
		
		if (sidebarURL == computedURL) {
			this.setAttribute("class", "active"); //For Most Browsers
			this.setAttribute("className", "active"); //For IE; harmless to other browsers.
			return true;
		}

		var isProductPage = currentURL.indexOf("http://www.echipamentmilitar.ro/produse/");
		if(isProductPage != -1) {
								// Obtin SKU si verific categoria
								var newSku = currentURL.split("/");
								newSku.reverse();
								var sku = newSku[1];
					
																if (sidebarURL == 'http://www.echipamentmilitar.ro/airsoft/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/nikon/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/victorinox/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/muela/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/leatherman/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/marttini/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/opinel/' + sku) {
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
								}
								if (sidebarURL == 'http://www.echipamentmilitar.ro/promotii/') 
									{
									this.setAttribute("class", "active"); //For Most Browsers
									this.setAttribute("className", "active"); //For IE; harmless to other browsers.
									return true;
									};
							} 
							else {
										
								};
	}
});
	
	/*$('#morefiltre').hide();
	$('a.expand').click(function(){
								 if($('#morefiltre').css('display')=='block') {
								 	 $('a.expand').css("background-image","url(images/expand.png)");	 
									 $('#morefiltre').slideUp("slow"); 
								 } else {
									 $('a.expand').css("background-image","url(images/expand2.png)");	
									 $('#morefiltre').slideDown("slow"); 
									 }
								 
								 });*/
	

	
	
	

});

function gotolink(linker) {
	window.location = linker;
}


