function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
 
function _compaerTableInit()
{
	
	$('.compaerLink').click( function(){ 
									  
									  self.opener.location = this;
									  return false;})
	$(".opt_c_selector").each( function(i,u){$(u).hover( function(){  _selector =$(this).attr('lang');   $(_selector).addClass('compaer_hover');}	,
														function(){  _selector =$(this).attr('lang');   $(_selector).removeClass('compaer_hover');}	
																	
																	)	
										}
										)
}
/*setTimeout("getBP()",10000)*/;
$(document).ready(function() {	
				
				
	ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})



$("ul.parentul li ul li:has(ul)").find("a:first").append(" &raquo; ");			
//$("ul.parentul li ul").addClass("rounds4");
								
	McsMarquee(20);
	MagicIsNew();
	__loader();
	getBP(CURRENT_LNG);
	CardProductQty();
	
	
	$(".search_content").hide();
	$(".advsearch_title").click(
		function()
		{
			$('.search_content').slideToggle(150);
			$('#toggler').toggleClass("btn-open");
			return false;
		}
	);
	
	
	$(".compaers").button({text: false,icons: {primary:'ui-icon-check'}});
	
	
	$(".addToCart").button({text: false,icons: {primary:'ui-icon-cart'}});
	$(".stock_disabled").button( "option", "disabled", true );
	
	$(".print_preview").button({text: true,icons: {primary:'ui-icon-print'}});
	
	$(".print_preview").click( function(){ 
										
										 window.open (this,"mywindow","menubar=0,resizable=0,width=1003,height=450,scrollbars=1");
										 return false;
										
										})
	$(".stock_disabled").click( function(){ $(this).removeAttr('href');return false;})
	$(".stock_enabled").click( function()
									{
										var _title =$(this).attr("title");
										$.get(this,function(data)
															{
																var _dialog = document.createElement("div");
																
																_dialog.id= "add-to-card-popUp";
																$(_dialog).attr("title",_title);
																$(_dialog).html(data);
																
																
																document.body.appendChild(_dialog);
																$('.cart_popupbuttons').button({text: true,icons: {primary:'ui-icon-cart'}});
																
																$("#qty").change( function()
																						   {
																							   var _v = this.value;
																							   _v = parseInt(_v);
																							   if(isNaN(_v))
																							   _v=1;
																							   this.value = _v;
																							   
																							});
																$("#qty").keyup(function(){ $(this).trigger('change')});
																$(".cart_popupbuttons").click( function(){ _shopingCardPopUpClick(this,_dialog);})
																$(_dialog).dialog({show: 'slide',"hide": 'slide',modal:true,width:500,height:300,close:function(){$(this).dialog('destroy');$(_dialog).remove() }});
																
															})
										return false;
									})
	$(".compaers").click( 
						 
						 function()
						 { 
						   var _value = this.value.split("|");
							 if(this.checked)
							 {
								
								 
								 $.post("/?action=addToComaer",{category:_value[0],product:_value[1]});
								 
								  
								 
								 
							 }else
							 {
								 $.post("/?action=removeToComaer",{category:_value[0],product:_value[1]});
							 }
						 });
    $('#slideshow').cycle({
		fx:     'scrollLeft',
		speed:  400, 
        timeout:     5000,
        pager:      '#pagernav'
    });
							
	
	/************************/
								
    jQuery('#mycarousel').jcarousel({
        //auto: 4,
		scroll:2,
		animation:2000,
		easing:'linear',
        wrap: 'circular',
        initCallback: mycarousel_initCallback,
		buttonNextEvent: 'mouseover',
		buttonPrevEvent: 'mouseover'
    });
	
	
	 jQuery('#mycarouse3').jcarousel({
        auto: 4,
		scroll:2,
		animation:1000,
		easing:'linear',
        wrap: 'circular',
        initCallback: mycarousel_initCallback,
		buttonNextEvent: 'mouseover',
		buttonPrevEvent: 'mouseover'
    });
    jQuery('#mycarousel2').jcarousel({
       // auto: 4,
		scroll:2,
		animation:2000,
		easing:'linear',
        wrap: 'circular',
        initCallback: mycarousel_initCallback,
		buttonNextEvent: 'mouseover',
		buttonPrevEvent: 'mouseover'
    });
	
	
	$('.compaer_link').click(function(){ 
									  
									  window.open (this,"mywindow","menubar=0,resizable=0,width=1003,height=410,scrollbars=1");
									  
									  return false;
									  
									  })
	/************************/
	
        /*$('div.demo marquee').marquee('pointer').mouseover(function () {
            $(this).trigger('stop');
        }).mouseout(function () {
            $(this).trigger('start');
        }).mousemove(function (event) {
            if ($(this).data('drag') == true) {
                this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
            }
        }).mousedown(function (event) {
            $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
        }).mouseup(function () {
            $(this).data('drag', false);
        });*/
		
		
		
		$("#slider").easySlider({
			prevId: 		'prevBtn',
			nextId: 		'nextBtn',	
			orientation:	'vertical'
	});

});
function reloadCaptcha(path)
{
	$("#captImage").attr('src','/kcaptcha/index.php?chk='+Math.random(150000));
}

function McsMarquee(K_speed)
{
	
	var m_marquee = $("#m_marquee");
	
	var m_marqueeW = m_marquee.outerWidth();
	var m_marqueeP = $("#m_marquee_c");
	
	var m_marqueePW =m_marqueeP.outerWidth();
	var m_marqueeWTo=(-m_marqueeW);
	m_marquee.css({left:m_marqueePW+5});
	
	var _speed = Math.round((m_marqueePW)/K_speed);
	
	m_marquee.animate({left:m_marqueeWTo},_speed*1000, function(){McsMarquee(K_speed);});
	
}
var CardProductQty=function()
{
	$("#b_qty").html("<img src='/images/b-loader.gif' width='16'/>")
	$.post("/?action=CardProductQty",function(data){ $("#b_qty").html(data);})
} 
var _shopingCardPopUpClick=function(button,_dialog)
{
		var _form =button.form;
		var _data = $(_form).serialize();
		var _url = _form.action;
		$(_dialog).dialog('disable');
		_lading = "<img src='/images/ajax-b-loader2.gif' alt='loading'/>"
		$(_dialog).dialog({'title':_lading});
		$.post(_url,_data,function(data)
								   {

																		CardProductQty();
									  									
																		var _button_id=button.id;
																		
									  									 if(_button_id == 'add_n_goto_cart')
																		 {
																			var _redir = $('#_shopingcardurl').val();
																			
																			window.location = _redir;
																		    return;
																		 }
																		 $(_dialog).dialog('close');
								   })
}

var initShopingCartForm = function()
{

	$(".remover").button({text: false,icons: {primary:'ui-icon-close'}});
	$(".remover").click( function()
								  {
									  
									var _data = $("#shoping_cart_sheet").serialize();
									var _url = $("#shoping_cart_sheet").attr('action');
									$("#shoping_cart_sheet").css({opacity:0.5});
									
									$.post(_url,_data,function(data){ $("#shoping_cart_sheet").replaceWith(data); initShopingCartForm(); CardProductQty();})
								  })
	$(".pqty").keyup( function(){
								   
								   val = this.value;
								   val = parseInt(val);
								   if(isNaN(val))
								   val =1;
								   if(val < 1)
								   val=Math.abs(val);
								   this.value = val;
								   
								});
	$(".pqty").change( function()
								{
									var _data = $("#shoping_cart_sheet").serialize();
									var _url = $("#shoping_cart_sheet").attr('action');
									$("#shoping_cart_sheet").css({opacity:0.5});
									
									$.post(_url,_data,function(data){ $("#shoping_cart_sheet").replaceWith(data); initShopingCartForm(); CardProductQty();})
								})
	
}

function MagicIsNew()
{
	$(".IsNew").each( function(i,e)
							   
							   {
								
								var _divIsNew = document.createElement("div");
								
								var _position = $(e).position();
								var _newImage = new Image();
								_divIsNew.appendChild(_newImage);
								_newImage.src = "/images/new-offer.png";
								_newImage.onload = function()
								{
									var _positions  =$(e).position();
									var _width  =$(e).width();
									var _height  =$(e).height();
									//_divIsNew.width = this.width;
									//_divIsNew.height = this.height;

									$(_divIsNew).css({
													 width:this.width,height:this.height,position:"absolute",top:_positions.top+3,left:_position.left+3,'z-index':this.style.zIndex+5});
									$(_divIsNew).insertBefore($(e));
									
									
								}
								
								
							    });
}

function getBP(_LNG)
{
	
	
	if($("#rbrice").length > 0){
	$("#rbrice").animate({opacity:0.2},1500);
	$.get("/"+_LNG+"/?external=1&itpl=default/best-price.tpl.html",function(datta){$("#rbrice").html(datta); $("#rbrice").animate({opacity:1},500)})
	setTimeout(getBP,10000,_LNG);
	}
}

var _laoderImage = null;
function __loader()
{
	_laoderImage = new Image();
	_laoderImage.src= "/images/loading2.gif";
	_laoderImage.onload = function()
	{
		this.style.display = "none";
		document.body.appendChild(this);
	}
}
