    $(document).ready(function(){
           	//if($('#productsLogos').length)$('#productsLogos').buildAnimatedGallery();
		   	//if($('#productsLogos').length)$('#productsLogos').buildProductsAnimatedGallery({step:1,speed:4000});
			if($('#productsLogos').length)$('#productsLogos').MySlider();
			if($('#sendToFriendDialog').length)$("#sendToFriendDialog").dialog({ modal: true ,resizable: false ,autoOpen: false });
		
			if ($('#map').length > 0)$('#map').setMapPoints();
			if($("#dialog").length)$("#dialog").dialog({ modal: true ,resizable: false ,autoOpen: false });
			if($('div.home-news-container').length)$('div.home-news-container').homeNewsBlock();
			
			if($('.print').length)$('.print').click(function(){print_page();});
			if($('.login').length)$('.login').click(function(){showLogin();});
			if($('#loginForm').length)$('#loginForm').click(function(){showLogin();});
			if($('.send-to-friend').length)$('.send-to-friend').click(function(){showfriend();});
			
			/*
			if ($('.prettyGallery').length > 0)$('.prettyGallery:last').prettyGallery({
					'navigation':'bottom',
					'itemsPerPage':5
				});*/
		
        }
    );






	$.fn.extend({
					buildProductsAnimatedGallery:function(config) {							
							new animatedGallery().init($(this),(config != undefined ? config : {} ));
					},
					
					homeNewsBlock				: function(){
							element = $(this);
							var step= parseInt($(this).children('div:first').height()) + 10;
							if($(element).children('div').length > 2){
								setInterval	(function(){
											$(element).children('div:first').animate({marginTop:'-'+step+'px'},function(){
																														$(this).appendTo($(this).parent()).css({marginTop:'0px'});
																														});
										}
										,4000);
							
							}
					}
				});
	
	
	
	
	
	function animatedGallery(){
		this.element	= null;
		this.animated	= null;
		this.count 		= 0;		
		this.speed		= 0;
		this.moveSpace	= 0;
		this.defaultMarginLeft = 0;
		
		this.init		= function(element, config){
			this.element	= element;
			
			this.defaultMarginLeft 		= parseInt(this.element.children('div.container').children('div.logos').children('a:first').css('margin-left')) * 2;
			var step 		= config.step != undefined  ? config.step : 1;
			var elementWidth= parseInt(this.element.children('div.container').children('div.logos').children('a:first').width()); 
			this.moveSpace	= step * (elementWidth + this.defaultMarginLeft) ;
			
			this.count		= this.element.children('div.container').children('div.logos').children('a').length;
			this.speed		= config.speed != undefined  ? config.speed : 4000;
			var obj			= this;		

 			if(this.count > 3){
				
				$(this.element).children('div.container').children('div.logos').width(this.moveSpace* $(this.element).children('div.container').children('div.logos').children('a').length +this.moveSpace);
				
				$(this.element).children('span.left').click(function(){
					obj.stop();	
			  		obj.element.children('div.container').children('div.logos').children('a:first').stop().animate({marginLeft:"-"+obj.moveSpace+"px"},{queue:true, duration:200, easing:'easeOutExpo',complete:function(){obj.reset({direction:'left'}); obj.start(); }});

				});
	
	
				$(this.element).children('span.right').click(function(){ 
					obj.stop();
					obj.reset({direction:'right'});
					obj.element.children('div.container').children('div.logos').children('a:first').stop().animate({marginLeft:obj.defaultMarginLeft+'px'},{queue:true, duration:200, easing:'easeOutExpo',complete:function(){ obj.start();  }});

				});
				
				this.start();
				
			}else{
				$(this.element).children('span.right, span.left').css({"visibility":"hidden"});
			}
			
		}
		
		
		
		
		
		this.start 		= function(){			
			var obj		= this;
			this.animated = setInterval( function(){
							
				obj.element.children('div.container').children('div.logos').children('a:first').animate({marginLeft:"-"+obj.moveSpace+"px"},{queue:true, duration:2000, easing:'easeOutExpo',complete:function(){obj.reset({direction:'left'}); }});
            } ,obj.speed  );			
		}
		
		
		this.reset = function(data){
			
			//var obj = this;
			
			
			
			
			if(data.direction == 'right'){
				this.element.children('div.container').children('div.logos').children('a:first').before(this.element.children('div.container').children('div.logos').children('a:last').css({marginLeft:'-'+this.moveSpace+"px"}));

				this.element.children('div.container').children('div.logos').children('a:last').stop().css({marginLeft:this.defaultMarginLeft+'px'});
			}else {
				this.element.children('div.container').children('div.logos').children('a:first').appendTo(this.element.children('div.container').children('div.logos')).css({marginLeft:this.defaultMarginLeft+'px'});
			
				this.element.children('div.container').children('div.logos').children('a:first').stop().css({marginLeft:this.defaultMarginLeft+'px'});
			}
		}
		
		
		this.stop 		= function(){
			var obj		= this;
			clearInterval(this.animated);
		}
		
		this.moveLeft 	= function(){
			
		}
		
		this.moveRight 	= function(){
			
		}
		
		this.set 		= function(){
			
		}
		
		this.get 		= function(){
			
		}
		
		return this;
		
	}
	

	
			
/*
	function animatedGallery(){
		this.animated	= null;
		this.goLeft     = true ;
		this.count 		= 0;
		this.space   	= 124;
		this.element	= null;
		this.expression	= '';
		this.width		= 0;
		
		
		
		this.init		= function(element){
			this.element	= element;
			this.width		= parseInt(this.element.children('div.container').children('div.logos').width());
	 		this.containerWidth =  parseInt(this.element.children('div.container').width());

			var obj			= this;
 
 
 			if(this.width - this.space > this.containerWidth){
				$(this.element).children('span.left').click(function(){
					  if((obj.width - (obj.count * obj.space) - (obj.space*3)) >= 0 ){
						  obj.stop();
						  obj.goLeft = true;
						  var moveLeft = ++obj.count * obj.space;
						  obj.element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:false, duration:400, easing:'easeOutExpo',complete:function(){obj.start();}});
					  
					  }
				});
	
	
				$(this.element).children('span.right').click(function(){ 
					  if(obj.count > 0){
						obj.stop();
						obj.goLeft = false;           
	
						var moveLeft = --obj.count * obj.space;
						obj.element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:false, duration:400, easing:'easeOutExpo',complete:function(){obj.start();}});
					  }
				});
				
				this.start();
				
			}
			
		}
		
		
		
		
		
		this.start 		= function(){
			
			var obj		= this;
			this.animated = setInterval( function(){
				if( obj.goLeft){
					var moveLeft = ++obj.count * obj.space;
					if(obj.width-((obj.count) * obj.space) <= obj.containerWidth)	obj.goLeft = false;	
				}else{
					var moveLeft = --obj.count * obj.space;
					if(obj.count <= 0)obj.goLeft = true;
				  	
				}
				
			  obj.element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:true, duration:1500, easing:'easeOutExpo',complete:function(){}});

            } ,4000  );
		}
		
		
		
		
		
		this.stop 		= function(){
			var obj		= this;
			clearInterval(obj.animated);
		}
		
		this.moveLeft 	= function(){
			
		}
		
		this.moveRight 	= function(){
			
		}
		
		return this;
		
	}
	


    var start       = null;
    var goLeft      = true ;
	var count 		= 0;
	var space   	= 124;
	
    $.fn.extend({
		
	  buildAnimatedGallery: function() {
        var element =  $(this);
		var width   = parseInt(element.children('div.container').children('div.logos').width());
        var containerWidth =  parseInt(element.children('div.container').width());


		
        function startAnimation(element){

            start = setInterval( function(){
              	


				if(goLeft){
					var moveLeft = ++count * space;
					if(width-((count) * space) - space <= containerWidth)	goLeft = false;				  
				 	
				}else{
					var moveLeft = --count * space;
					if(count <= 0)goLeft = true;
				  	
				}
				
			  element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:true, duration:1500, easing:'easeOutExpo',complete:function(){}});

            } ,4000  );
        }

        $(this).children('span.left').click(function(){
				  var element =  $(this).parent();  
                  var width   = parseInt(element.children('div.container').children('div.logos').width());

				  if((width - (count * space) - (space*3)) > 0 ){
					                
                  

					  clearInterval(start);
					  goLeft = true;
					  var moveLeft = ++count * space;
					  element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:false, duration:400, easing:'easeOutExpo',complete:function(){startAnimation(element);}});
				  
				  }




        }).click();

        $(this).children('span.right').click(function(){
				  var element =  $(this).parent();
                  if(count > 0){
					
					clearInterval(start);
					goLeft = false;           

					var moveLeft = --count * space;
					element.children('div.container').children('div.logos').stop().animate({left:"-"+moveLeft+"px"},{queue:false, duration:400, easing:'easeOutExpo',complete:function(){startAnimation(element);}});
				  }



        });

      }
	  

    });
	
	
	*/
	
	
	
	
	
	
	
	
	
	function login() {
		$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',true);
		$('#loginMessageFailure,#loginMessagesuccess').hide();
		$('#loginLoader').show();
		$.ajax({
			url: "index.php?pg=login&disable_rewrite=1&plain=1",
			type:"POST",
			async: true,
			dataType:'json',
			data: {
				plain:1,
				username:$("#frm_login").find("[name=username]").val(),
				password:$("#frm_login").find("[name=password]").val()
			},
			beforeSend: function(XMLHttpRequest) {
				
			},
			success: function(json){
				if(json.err) {
					$('#loginMessageFailure').html(json.msg).show();
				}else{
					$('#loginMessagesuccess').html(json.msg).show();
				}
				$('#loginLoader').hide();
				$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
				if(!json.err) {
					window.location.href=document.URL;
				}
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				alert('Server Error')
				$('#loginLoader').hide();
				$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
			}
		});
	}

	function showLogin() {
		$("#dialog").dialog('open');
		//$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
		//$('#loginMessageFailure,#loginMessagesuccess').hide();
	}
	
	
	$.fn.extend({
	  setMapPoints: function() {
		  if($(this).children('.points-container').children('.point').length){
				$(this).children('.points-container').children('.point').each(function(index,element){
																					   var x = $(this).attr('x');
																					   var y = $(this).attr('y');
																					   $(this).css({'left':x+'px','top':y+'px'}).click(function(){Tip("<div class='tooltip-content'>"+$(this).text()+"</div>");return false;}).mouseover(function(){Tip("<div class='tooltip-content'>"+$(this).text()+"</div>");}).mouseleave(function(){UnTip();});
																					});  
		  }
	  }
	});

	
	function fullwin(targeturl){
		window.open(targeturl,'', 'fullscreen,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0');
	}
	
	

/////////////////////////////////////////////////////////////////////	

	function print_page(){
		
				var disp_setting= "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=900, height=900, left=0, top=0"; 
				var content_value= $('#print-div').html(); 
				var docprint=window.open("","",disp_setting); 
				docprint.document.open(); 
				docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Arma</title><link rel="stylesheet" type="text/css" href="'+g_smarty_templatepath+'/cdn/images/style.css" media="all" />');
										
				docprint.document.write('</head><body onLoad="self.print()"><center><div><div style="width:100%;margin-left:0px; clear:left;float:left;"><img src="templates/cdn/images/13.png" align="left"/></div><div style="clear:left;float:left;">');          
				docprint.document.write('<table class="print-page"><thead></thead><tfoot valign="bottom" ></tfoot><tbody><tr><td class="page-tbody-container">'+content_value+'</td></tr></tbody></table></div>');          
				docprint.document.write('</div></center></body></html>'); 
				 
				docprint.focus(); 
				docprint.document.close();
		
		/*	var headstr = "<html><head><title></title></head><body>";
			var footstr = "</body>";
			var newstr = document.getElementById('print-div').innerHTML;
			var oldstr = document.body.innerHTML;
			document.body.innerHTML = headstr+newstr+footstr;
			window.print(); 
			document.body.innerHTML = oldstr;
			return false;*/
		}
		
		//////////
		
		
	function showfriend() {
		$("#sendToFriendDialog").dialog('open');
	}	
		
		
	function Sendtofriend(){
		//	alert('I AM INSIDE THE FUNCTIONS ') ;
			$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',true);
			$('#sendToFriendDialogMessageFailure,#sendToFriendDialogMessagesuccess').hide();
			$('#sendToFriendDialogLoader').hide();
					$.ajax({
					url: "index.php?pg=sendtofriend&disable_rewrite=1",
					type:"POST",
					async: true,
					dataType:'json',
					data: {
						friendMail:$("#frm_sendtofriend").find("[name=friendMail]").val(),
						userdMail:$("#frm_sendtofriend").find("[name=userdMail]").val(),
						cur_url:$("#frm_sendtofriend").find("[name=cur_url]").val()
					},
					beforeSend: function(XMLHttpRequest) {
					},
					success: function(json){
								if(json.err) {
								$('#sendToFriendDialogMessageFailure').html(json.msg).show();
								}else{
									$('#sendToFriendDialogMessagesuccess').html(json.msg).show();
								}
								//alert('success') ;
								$('#sendToFriendDialogLoader').hide();
								$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',false);	
						
								if(!json.err) {
								window.location.href=$("#frm_sendtofriend").find("[name=cur_url]").val();
								}
						
					
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						alert('Server Error') ;
						$('#sendToFriendDialogLoader').hide();
						$("#frm_sendtofriend").find("[name=friendMail],[name=userMail],[name=submit]").attr('disabled',false);
					}
				});
		}	
		
		


function slideShow() {

	//Set the opacity of all images to 0
	$('#imageGallerie p').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#imageGallerie p:first').css({opacity: 1.0});
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	//setInterval('imageGallerie()',6000);
	imageGallerie();
}

function imageGallerie() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#imageGallerie p.show')?  $('#imageGallerie p.show') : $('#imageGallerie p:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#imageGallerie p:first') :current.next()) : $('#imageGallerie p:first'));	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000, function(){setTimeout("imageGallerie()", 6000);});

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');

}






	$(document).ready(function(){
							   		if($('.products-logos').length)$('.products-logos').MySlider();
								});

	$.fn.extend({
		MySlider:function(){
			new MySlider().init(
					   	{
							element : $(this) 	,
							speed	: 500        
						}
				  );
			}
	});



	/* SLIDER */
	function MySlider(){
		
		this.element 	= '';
		this.interval	= null;
		this.delay		= 2000;
		this.speed	 	= 1000;
		this.step		= 0;
		this.leftArrow	= '';
		this.rightArrow	= '';
		this.itemsContainer= '';
		this.DMarginLeft= 0;
		this.activeImage= '';
		
		var me = this;
		
		
		this.init 		= function(settings){
			this.element 		= settings.element;
			this.speed			= settings.speed != undefined ? settings.speed : this.speed;
			this.itemsContainer	= $(this.element).find('ul');
			this.leftArrow		= $(this.element).find('.left-arrow');
			this.rightArrow		= $(this.element).find('.right-arrow');			
			this.step			= this.itemsContainer.children('li').width();

			if(this.itemsContainer.children('li').length > 3){
				this.leftArrow.click(function(){	me.moveLeft();	});
				this.rightArrow.click(function(){  	me.moveRight();	});			
				this.start();
			}
			
			this.itemsContainer.children('li').each(
							function(index, element){
								$(this).children('a')
									.mousemove(function(){
										
										var backGround = $(this).css('background-image');										
										if(backGround != '' && backGround != 'none' && backGround != undefined)$(this).attr('backGround', backGround);//me.activeImage = backGround;
										
										me.stop();
										if(!$(this).children('img').length){
											if($(this).css('background-image').indexOf('\"'))$slices = $(this).css('background-image').split("\"");
											else if($(this).css('background-image').indexOf('\''))$slices = $(this).css('background-image').split("'");
											$(this).css("position","relative");
											$(this).append("<img src='"+$slices[1]+"' alt='' style='position:absolute;   width:"+(parseInt(parseInt($(this).width()) * 120 / 100 ))+"px; left:-"+(parseInt(parseInt(parseInt($(this).width()) * 120 / 100 ) - parseInt($(this).width())) / 2 )+"px;  height:"+(parseInt(parseInt($(this).height()) * 120 / 100 ))+"px; top:-"+(parseInt(parseInt(parseInt($(this).height()) * 120 / 100 ) - parseInt($(this).height())) / 2 )+"px' />");
											
											
											$(this).css('background-image', '');
											
											
											
											$(this).children('img').mouseout(function(){
																				var objMe = $(this);
																				var parentContainer = $(this).parent();
																				setTimeout(function(){			   
																								var backGround = me.activeImage;
																								parentContainer.css('background-image', parentContainer.attr('backGround'));
																								//alert($(this).attr('src'));
																								objMe.remove();																									
				
																								me.stop();
																								me.start();
																							},100);
																			});
										}
									});
									
							});
			
		}
		
		this.start 		= function(){
			this.interval = setTimeout(function(){me.moveLeft();}, me.delay);
		}
		
		this.stop 		= function(){
			clearTimeout(me.interval);
		}
		
		this.moveLeft 	= function(){			
			this.stop();
			this.itemsContainer.children('li:first').stop().animate({marginLeft:"-"+me.step+"px"},me.speed, function(){
				$(this).appendTo(me.itemsContainer).css({marginLeft:me.DMarginLeft+'px'}); me.start(); 
																											  });
		}
		
		this.moveRight 	= function(){
			this.stop();
			this.itemsContainer.children('li:first').before(me.itemsContainer.children('li:last').css({marginLeft:"-"+me.step+'px'}));
			this.itemsContainer.children('li:first').animate({marginLeft:"+"+me.DMarginLeft+"px"}, me.speed, function(){ me.start();});
		}
		
		return this;
		
	}

