window.addEvent('domready', function() {
	        
            
        $(document).scroll(function(){
            /*if(($(document).height()-$('#post-30').height()-$('#footer').height()-$('#after-content').height())<=($(window).height()+$(document).scrollTop())){
                var page = $("#cat_cur_page").val();
		var length = $("#cat_length").val();
		var pages = $("#cat_pages").val();
		var ids = $("#cat_ids").val();
		page++;
		if(page == pages)$('#giveMeMore').hide();
                var prices = $('#priceDiv').myslider('option','values');
		collect (ids,page,pages,length,prices[0],prices[1]);
		$("#cat_cur_page").val(page);
            }*/
            });
	$('#giveMeMore').add('.giveMeMore').click(function(){
            var els = {}
                if($(this).find('.cat_cur_page').size()>0){
                    var page = $(this).find(".cat_cur_page").val();
                    var length = $(this).find(".cat_length").val();
                    var pages = $(this).find(".cat_pages").val();
                    var ids = $(this).find(".cat_ids").val();

                    els.cpel = $(this).find(".cat_cur_page");
                    els.lel = $(this).find(".cat_length");
                    els.pel = $(this).find(".cat_pages");
                    els.iel = $(this).find(".cat_ids");
                }
                else{
                    var page = $("#cat_cur_page").val();
                    var length = $("#cat_length").val();
                    var pages = $("#cat_pages").val();
                    var ids = $("#cat_ids").val();

                    els.cpel = $(this).find("#cat_cur_page");
                    els.lel = $(this).find("#cat_length");
                    els.pel = $(this).find("#cat_pages");
                    els.iel = $(this).find("#cat_ids");
                }
		page++;
		if(page == pages)$(this).hide();
                if($('#priceDiv').size())var prices = $('#priceDiv').myslider('option','values');
                else var prices = [0,999999999];
                if($(this).parent().find('table.CatContent > tbody').size() == 1)var toApp = $(this).parent().find('table.CatContent > tbody');
                else var toApp = $(this).parent().find('table.CatContent');
		collect (ids,page,pages,length,prices[0],prices[1],toApp);
		els.cpel.val(page);

	});
        var ua = navigator.userAgent,
         click = (ua.match(/iPad/i)) ? "click" : "click";
         if(navigator.platform!='iPad'){
         $('.itemproduct').live('mouseover',function(){
             $(this).addClass('hover');
             });
          $('.itemproduct').live('mouseout',function(){
             $(this).removeClass('hover');
             });

	$('.box-readmore').live(click,function(){
		getPopup($(this).attr('product'));
		return false;
	});
        var els = '.itemWrap > .itemproduct';
	}
        else{  var els = '.itemWrap';}
        $(els).live(click,function(){
            if($(this).attr('product')) var product = $(this).attr('product');
            else var product = $(this).find('.box-readmore').attr('product');
            getPopup(product);
            return false;
        });


	$(".catalogFilters select").change(function(e){
			if($(this).val() != '#')
				document.location = $(this).val();
		});
         makePriceSlider('priceDiv');

         $('.collection_btn').add('.closeBtn').click(function(){
             var gal = $(this).parents('.brand_gallery');
             var col = gal.find('.b_g_collection');
             var coli = gal.find('.b_g_collection_inner');
             if(col.height()>0)
                 var height = 0;
             if(col.height()<coli.height())
                 var height = coli.height();
             if(col.height()<coli.height() && col.height()>0)
                 var height = 0;
             if(coli.height()>(gal.height()-gal.find('.b_g_cats').height()))
                 var height = gal.height()-gal.find('.b_g_cats').height()
             col.animate({height:height},400);
         });

         $('p.promheader').toggle(function(){
             $(this).parent().find('.prom_product').show();
             $(this).addClass('expand');
         },function(){
             $(this).parent().find('.prom_product').hide();
             $(this).removeClass('expand');
         });

	$('#led').click(function() {
		getPopupLed(); 
	});
});
function makePriceSlider(containerId){
    if($('#'+containerId).size() == 0)return false;
    var data = {};
    data.pricebegin = $('#'+containerId+' .min-price').val();
    data.priceend = $('#'+containerId+' .max-price').val();

    ar1 = Math.round(((data.pricebegin-data.pricebeginmin) / (data.priceendmax-data.pricebeginmin))*100);
    ar2 = Math.round(((data.priceend-data.pricebeginmin) / (data.priceendmax-data.pricebeginmin))*100);
    ar1 = parseInt(data.pricebegin);
    ar2 = parseInt(data.priceend);
    delta = Math.round((data.priceend - data.pricebegin)/100);
    var step=100;
    var slide = $('#'+containerId).myslider({
            range: true,
            min: ar1,
            max: ar2,
            values: [ar1,ar2],
            acceptedvalues: [ar1,ar2],
            step:step,
            orientation:'horizontal',
            create:function(){
                    $(".ui-slider-horizontal .ui-slider-handle:eq(0)").css('background','url(/templates/beez5/images/slider/array-down.png) left bottom no-repeat');
                    $(".ui-slider-horizontal .ui-slider-handle").css('margin-left','-6px');
            },
            change: function(event, ui) {
                    var beginprice = ui.values[0];
                    var endprice = ui.values[1];
                    var length = $("#cat_length").val();
                    var pages = $("#cat_pages").val();
                    var page = 0;
                    var ids = $("#cat_ids").val();
                    $('.catalog_row').remove();
                    collect (ids,page,pages,length,beginprice,endprice);
            },
            slide: function(event, ui) {
                 var beginprice = ui.values[0];
                 var endprice = ui.values[1];
                 $('#beginprice').val(beginprice);
                 $('#endprice').val(endprice);
            }
    });

    if(navigator.platform=='iPad') slide.addTouch();

    $('#beginprice').add('#endprice').change(function(){
						var beginprice = parseInt($('#beginprice').val());
						var endprice = parseInt($('#endprice').val());
						var scope = parseInt(data.priceend-data.pricebegin);
						//var slidermin = parseInt(data.pricebegin)+parseInt($('#'+containerId).myslider('option','min'))*scope/100;
						//var slidermax = parseInt(data.pricebegin)+parseInt($('#'+containerId).myslider('option','max'))*scope/100;
						var slidermin = parseInt(data.pricebegin);
						var slidermax = parseInt(data.priceend);
						//var slider = $('#'+containerId).myslider('option','values');
						if(beginprice<=slidermin){
							beginprice = slidermin;
						}
						if(endprice>=slidermax){
							endprice = slidermax;
						}
						if(endprice<=beginprice){
							endprice = beginprice;
						}
						if(beginprice>=endprice){
							beginprice = beginprice;
						}
						//$('#'+containerId).myslider('option','values',[ Math.round(100*(beginprice-data.pricebegin)/scope), Math.round(100*(endprice-data.pricebegin)/scope)]);
						if($(this).is('#beginprice')){
                                                    $('#'+containerId).myslider('values',0, beginprice);
                                                }
                                                else $('#'+containerId).myslider('values',1, endprice);
					});
}
function collect (ids,page,pages,length,beginprice,endprice,toApp){
    if(page == pages)$('#giveMeMore').hide();
    if(toApp===undefined){
        if($('table.CatContent > tbody').size() == 1)var toApp = $('table.CatContent > tbody');
        else var toApp = $('table.CatContent');
    }
    toApp.append('<tr class="preloader_row"><td colspan="4"><img src="/images/preloader-red.gif" /></td></tr>');
    var itemid = getParameter(window.top.location.search.substring(1),'Itemid');
    var z = $('td.titem:last').css('z-index');
    var noBrand = '';
    if(toApp.find('.titem:eq(0) .productBrand').size()==0)noBrand='&noBrand=1';
    urls = '/ajax/collect.php';
            $.ajax({
                    url: urls,
                    cache:false,
                    context:toApp,
                    type:'POST',
                    data:'prodimage='+ids+'&page='+(page)+'&length='+length+'&z='+z+'&beginprice='+beginprice+'&endprice='+endprice+'&Itemid='+itemid+noBrand,
                    success: function(data) {
                        try{
                            var data1 = JSON.parse(data);
                            data = data1;
                        }catch(e){
                            var str = '';
                            //for(var key in e) str +='\n'+key+': '+ e[key];
                            //alert(str);
                            //alert(JSON.parse);
                            }
                            if(data.page<data.pages){
                                $('#giveMeMore').show();

                                $('#cat_pages').val(data.pages);
                                $('#cat_cur_page').val(data.page);

                                $(this).parent().find('.giveMeMore').show();
                                $(this).parent().find('.cat_pages').show();
                                $(this).parent().find('.cat_cur_page').show();

                            }
                            else $('#giveMeMore').hide();
                            //if($('table.CatContent > tbody').size() == 1)var toApp = $('table.CatContent > tbody');
                            //else var toApp = $('table.CatContent');
                            toApp = $(this);
                            $('tr.preloader_row').remove();
                            toApp.append(data.html);
                            if($.browser.msie){
                                    /*h = 0;
                                    $('.catalog_row').each(function(){h=h+ $(this).height();});alert (h);
                                    $('.CatContent').height(h);*/
                            }
                    }
            });
}

function getPopupLed() {
	$('<div class="whitecover" style="width:'+'100%'+';height:'+'100%'+';top:0;left:0;position:absolute;z-index:100;"><img src="/images/preloader-red.gif" class="preloader" /></div>').appendTo('#main');
	$('img.preloader').css('position','fixed').css('top',$(window).height()/2-15).css('left','50%').appendTo('.whitecover');
	if($('div.popup').size()==0)$('#main').append('<div class="popup" style="display:none;width: 701px; height: 567px;  left: 347px; background: none repeat scroll 0pt 50% transparent;"></div>');
	var left = ($("body").width()-774)/2;
	var top = $(document).scrollTop() + ($(window).height()-567)/2;
	$("div.popup").html('<img src="/images/preloader-red.gif"/>');
	$("div.popup").css("width","774px").css("height","567px").css("top",top+"px").css("left",left+"px").css("background","white").show();
	urls = '/ajax/led.php';
	$.ajax({
		url: urls,
		cache:false,
		success: function(data) {
			$("div.popup").html(data);
			$("div.popup").css("background","0");
			Cufon.replace(
				'.helios',
				{fontFamily: 'Calibri',hover: true}//ul#topnav li a.mainitem,
			);
			Cufon.replace( 
				'.heliosbold',
				{fontFamily: 'Calibri',hover: true}//ul#topnav li a.mainitem,
			);
			Cufon.replace(
				'.vetren',
				{fontFamily: 'Opium',hover: true}//ul#topnav li a.mainitem,
			);

			$("td.chooseItem .colorPic").mouseover(function(){
				$("td.chooseItem .toparrow").removeClass("showTopArrow");
				$("td.chooseItem .bottomarrow").removeClass("showBottomArrow");
				$(this).parents("td.chooseItem").find(".toparrow").addClass("showTopArrow");
				$(this).parents("td.chooseItem").find(".bottomarrow").addClass("showBottomArrow");
			});

			$(".popup div.closeBtn").click(function(){
				$(this).parents("div.popup").hide();
				$("div.coverAll").hide();
				$('.whitecover').remove();
			});

			$(".scroller").each(function(){
				$(this).tinyscrollbar({sizethumb: 35});
			});
		} 
	});
}
 
function getPopup(product){
                if($('.whitecover').size() == 0){
                    $('<div class="whitecover" style="width:'+'100%'+';height:'+'100%'+';top:0;left:0;position:absolute;z-index:100;"><img src="/images/preloader-red.gif" class="preloader" /></div>').appendTo('#main');
                    $('img.preloader').css('position','fixed').css('top',$(window).height()/2-15).css('left','50%').appendTo('.whitecover');
                }
		if($('div.popup').size()==0)$('#main').append('<div class="popup" style="display:none;width: 701px; height: 567px;  left: 347px; background: none repeat scroll 0pt 50% transparent;"></div>');
		$('div.popup').html('');
                var itemid = getParameter(window.top.location.search.substring(1),'Itemid');
		urls = '/ajax/product.php?id='+product+'&Itemid='+itemid;
		$.ajax({
			url: urls,
			cache:false,
			success: function(data) {
				$('div.popup').html(data);
                                var ua = navigator.userAgent,
                                amiPad = ua.match(/iPad/i);
                                //if(amiPad)alert((amiPad?$(document).height():$(window).height())/2 - 280);
				$('div.popup').css('top',(amiPad?($(window).scrollTop()+$(window).height()/2- 280):($(window).height()/2- 280)) );
				$('div.popup').css('left',$(window).width()/2 - 350);
				$('div.popup').show();

			$("div.popup").css("background","0");
		Cufon.replace(
					'.helios',
					{fontFamily: 'Calibri',hover: true}//ul#topnav li a.mainitem,
			);
		Cufon.replace(
					'.heliosbold',
					{fontFamily: 'Calibri',hover: true}//ul#topnav li a.mainitem,
			);
		Cufon.replace(
					'.vetren',
					{fontFamily: 'Opium',hover: true}//ul#topnav li a.mainitem,
			);


		$("td.chooseItem .colorPic").mouseover(function(){
			$("td.chooseItem .toparrow").removeClass("showTopArrow");
			$("td.chooseItem .bottomarrow").removeClass("showBottomArrow");
			$(this).parents("td.chooseItem").find(".toparrow").addClass("showTopArrow");
			$(this).parents("td.chooseItem").find(".bottomarrow").addClass("showBottomArrow");
		});

		$(".popup div.closeBtn").click(function(){
			$(this).parents("div.popup").hide();
					$("div.coverAll").hide();
                                        $('.whitecover').remove();
		});

		$("td.popupTab").click(function(){
			$("td.popupTab").children("table").removeClass("popupTabAct").addClass("popupTab");
			$(this).children("table").toggleClass("popupTab").toggleClass("popupTabAct");
			$("table.popupMain").hide();
			var id = $(this).children("input").val();
			$("#"+id).show();
			if (id=='tab1') 
			$(".popupMain").css('vertical-align','middle');
			else
			$(".popupMain").css('vertical-align','top');
			$("#"+id+" .scroller").each(function(){
				//$(this).tinyscrollbar({sizethumb: 35});
			});

			Cufon.replace(
					'.helios',
					{fontFamily: 'Calibri',hover: true}//ul#topnav li a.mainitem,
			);
                            if(id=='tab3')loadMap();
		});


			}
		});

}
function brandslides(id){
                        var total = $('#'+id+' .b_g_container img').size();
                        var index = $('#'+id+' .slide-current').index();
                        if(index < total - 1){
                            index ++;
                        }
                        else index = 0;
                        $('#'+id+' .slide-current').css('z-index','2');
                        $('#'+id+' .b_g_container img:eq('+index+')').css('z-index','1').show();
                        $('#'+id+' .slide-current').animate({
                            opacity: 0
                          }, 2000, function() {
                            $(this).hide().animate({
                                opacity: 1
                              },0);
                          }).removeClass('slide-current')
                        $('#'+id+' .b_g_container img:eq('+index+')').addClass('slide-current');
                }

function getParameter ( queryString, parameterName ) {
   // Add "=" to the parameter name (i.e. parameterName=value)
   var parameterName = parameterName + "=";
   if ( queryString.length > 0 ) {
      // Find the beginning of the string
      begin = queryString.indexOf ( parameterName );
      // If the parameter name is not found, skip it, otherwise return the value
      if ( begin != -1 ) {
         // Add the length (integer) to the beginning
         begin += parameterName.length;
         // Multiple parameters are separated by the "&" sign
         end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
         end = queryString.length
      }
      // Return the string
      return unescape ( queryString.substring ( begin, end ) );
   }
   // Return "null" if no parameter has been found
   return "null";
   }
}



$.google = new Object();
$.google.markers = new Array();
$.google.map = null;
$.google.infoWindows = new Array();

 function loadMap(){
		if($("#google-map").size()==0) return;
		var coords = new Array();
		var lat = lng = 0;
		for(var i = 0;i<$('.StLat').size();i++){
			coords[i] = new Array();
			lat += coords[i][0] = parseFloat($('.StLat:eq('+i+')').val());
			lng += coords[i][1] = parseFloat($('.StLng:eq('+i+')').val());
			coords[i][2] = parseFloat($('.StLng:eq('+i+')').attr('bout'));
		}
		var latlng = new google.maps.LatLng(lat/i, lng/i);
		var myOptions = {
		  zoom: 12,
		  center: latlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		$.google.map = new google.maps.Map(document.getElementById("google-map"),
			myOptions);
			var LatLngList = new Array();
		for(i=0;i<coords.length;i++){

			var image = $.google.markerCaptions[coords[i][2]]['normal'];
			  var myLatLng = new google.maps.LatLng(coords[i][0], coords[i][1]);
			  var beachMarker = new google.maps.Marker({
				  position: myLatLng,
				  map: $.google.map,
				  icon: image,
				  title: $.google.markerCaptions[coords[i][2]]['title']
			  });
                          if($.google.markers===undefined)$.google.markers = new Array();
			  $.google.markers[coords[i][2]] = beachMarker;
                          if($.google.infoWindows===undefined)$.google.infoWindows = new Array();
			  $.google.infoWindows[coords[i][2]] = new google.maps.InfoWindow({
														content: $.google.markerCaptions[coords[i][2]]['content'],
														maxWidth:500
													});
			  eval("google.maps.event.addListener($.google.markers["+coords[i][2]+"], 'click', function() { for(var i = 0;i<$.google.infoWindows.length;i++){if($.google.infoWindows[i] !== undefined)$.google.infoWindows[i].close();}$.google.infoWindows["+coords[i][2]+"].open($.google.map,$.google.markers["+coords[i][2]+"]); });");
			LatLngList[i] = myLatLng;
		}
		if(i>1){
			var bounds = new google.maps.LatLngBounds ();
			//  Go through each...
			for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
			  //  And increase the bounds to take this point
			  bounds.extend (LatLngList[i]);
			}
			//  Fit these bounds to the map
			$.google.map.fitBounds (bounds);
		}
}

