var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;
var left=0;
var total=0;

function ddm_open()
	{  
		ddm_canceltimer();
		ddm_close();
		ddmenuitem = $(this).find('ul').css('visibility', 'visible');
	}

	
function ddm_close()
	{  
		if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	}

	
function ddm_timer()
	{ 
		closetimer = window.setTimeout(ddm_close, timeout);
	}

	
function ddm_canceltimer()
	{  
		if(closetimer)
		{  
			window.clearTimeout(closetimer);
			closetimer = null;
		}
	}

function pos_slider()
	{
		total = $('#promo-list li').size();
		var size = total * 166;
		$('#promo-list').css('width',size+'px');
	}
	
function send_to_left_btn(param)
{
	var flash = document.getElementById("go-left");
	flash.callLeftBtn(param);
}

function send_to_right_btn(param)
{
	var flash = document.getElementById("go-right");
	flash.callLeftBtn(param);
}

function slider_left()
 {
if (left < (total-4))
  { 

   left=left+1;
   var aux=left*(-166);
   $('#promo-list').stop().animate({marginLeft: aux},  {duration:1200} );
  }
  if (left==0)
  { 
   /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-off.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-on.jpg') no-repeat center center");*/
   send_to_left_btn(0);
   send_to_right_btn(1);
  }
  else if (left==total-4)
  { 
   /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-on.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-off.jpg') no-repeat center center");*/
   send_to_left_btn(1);
   send_to_right_btn(0);
  }
  else
  { 
  /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-on.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-on.jpg') no-repeat center center");*/
   send_to_left_btn(1);
   send_to_right_btn(1);
  }
 }
 
function slider_right()
 {
if (left > 0 )
  {
   
   left=left-1;
   var aux=left*(-166);
   $('#promo-list').stop().animate({marginLeft: aux},  {duration:1200} );
  }
  if (left==0)
  { 
   /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-off.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-on.jpg') no-repeat center center");*/
    send_to_left_btn(0);
   	send_to_right_btn(1);
  }
  else if (left==total-4)
  { 
   /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-on.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-off.jpg') no-repeat center center");*/
    send_to_left_btn(0);
   	send_to_right_btn(1);
  }
  else
  { 
   /*$('#go-left').css('background',"url('/img/"+theme+"/slider-left-on.jpg') no-repeat center center");
   $('#go-right').css('background',"url('/img/"+theme+"/slider-right-on.jpg') no-repeat center center");*/
    send_to_left_btn(1);
  	send_to_right_btn(1);
  }
 }

 
 function moreless(x)
 {
  $('#prod-list a').each(
   function(i)
   {
    if (i>x)
    $(this).css('display','none');
    else $(this).css('display','block');
   }
  );
 }
	
$(document).ready(function()
	{  
		//$('marquee').marquee();
		var total;
		$('#menu-main > li').bind('mouseover', ddm_open);
		$('#menu-main > li').bind('mouseout',  ddm_close);
		$('#go-left').bind('click', slider_right);
		$('#go-right').bind('click', slider_left);
		pos_slider();
		moreless(40);
		
		$('ul#menu-main > li:last a span.right').css('background-image','none');
		$('#menu-main li').hover(
		function(){
			$('a span',this).css('background-image', 'url(/img/'+theme+'/menu/menu-on.gif)');
			$('a span',this).css('padding-left', '6px');
			$('a span',this).css('padding-right', '6px');
			
			$('a span.left',this).css('background-image', 'url(/img/'+theme+'/menu/menu-left-on.gif)');
			$('a span.left',this).css('padding', '0');
			$('a span.left',this).css('margin-left', '-6px');
			
			$('a span.right',this).css('background-image', 'url(/img/'+theme+'/menu/menu-right-on.gif)');
			$('a span.right',this).css('padding', '0');
			$('a span.right',this).css('margin-right', '-6px');
		},
		function(){
			$('a span',this).css('background-image', '');
			$('a span',this).css('padding', '0');
			
			$('a span.left',this).css('background-image', '');
			$('a span.left',this).css('padding', '0');
			$('a span.left',this).css('margin', '0');
			
			$('a span.right',this).css('background-image', '');
			$('a span.right',this).css('padding', '0');
			$('a span.right',this).css('margin', '0');
			
			//$('ul#menu-main > li:last a span.right').css('background-image','none');
		}
		);
		var tempW=0;
		var tempWE=0;
		$('#menu-main>li').each(function(){
			tempW=tempW+$(this).width();
		});
		tempWE=($('#menu-main').width()-tempW)/($('#menu-main>li').size()+1);
		tempWE=parseInt(tempWE);
		$('#menu-main>li').css('margin-right',tempWE+'px');
		$('#menu-main>li').eq(0).css('margin-left',tempWE+'px');
	  $('#more-prod-list').toggle(
	   function(){ 
	    moreless($('#prod-list a').size());
	    $('#more-prod-list a').html('Mai putini producatori');
	   },
	   function(){
	    $('#more-prod-list a').html('Vezi toti producatorii');
	    moreless(40);    
	   }
	  );
		if (theme=="")
			//swfobject.embedSWF("/swf/slider_homepage.swf", "promo", "990", "290", "9.0.0", "/swf/expressInstall.swf", {xml_path:"/swf/images_homepage"+(Math.floor(Math.random()*2+1))+".xml"}, {wmode:"transparent"}, {});
			swfobject.embedSWF("/swf/slider_homepage.swf", "promo", "990", "290", "9.0.0", "/swf/expressInstall.swf", {xml_path:"/swf/images.xml"}, {wmode:"transparent"}, {});
		else	
			swfobject.embedSWF("/swf/slider_"+theme+".swf", "promo", "990", "290", "9.0.0", "/swf/expressInstall.swf", {xml_path:"/swf/images.xml"}, {wmode:"transparent"}, {});

		var flashvars = {
		  arrow_color: color
		};
		var params = {wmode:"transparent"};
		var attributes = {};	
		swfobject.embedSWF("/swf/arrow_right.swf", "go-right", "63", "142", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);	
		swfobject.embedSWF("/swf/arrow_left.swf", "go-left", "63", "142", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);
		$('#landing-bose').slideUp();
		$('#landing-bose-t').toggle(function(){
			$('#landing-bose').slideDown();
		},function(){
			$('#landing-bose').slideUp();
		});
	});
document.onclick = ddm_close;

 $("a").filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    }).attr('target', '_blank');