﻿var zindex = 101;
var PageName
var skinPath
$(document).ready(function() {


 //lightbox init
    
    $('.lightbox').prepend('<a class="btn-close-lightbox"><IMG alt="" src="/Portals/Laguna/X.gif" width=15 height=15> סגור</a>');
    $('.lightboxDown').prepend('<a class="btn-close-lightbox"><IMG alt="" src="/Portals/Laguna/X.gif" width=15 height=15> סגור</a>');
    $('body').append('<div class="overlay"></div>');
    $('.overlay').hide();
    
    $('.btn-close-lightbox, .overlay').click(function() {
        $('.lightbox').hide();
        $('.lightboxDown').hide();
        $('.overlay').hide();
    });
    
    $('a.btn-open-lightbox').click(function(e) {
        e.preventDefault();
        openLightbox($(this).attr('href'));
    });


	$(".MEZOOlogin .MEZOOsignintable DIV.LoginPanel .StandardButton").attr("value", "היכנס");

// hiding the sort options in shop
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=ProductNumber], .MEZOOsortdiv .CATNormalDropDownList option[value=ProductNumber DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=EAN], .MEZOOsortdiv .CATNormalDropDownList option[value=EAN DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=ISBN], .MEZOOsortdiv .CATNormalDropDownList option[value=ISBN DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=Free1], .MEZOOsortdiv .CATNormalDropDownList option[value=Free1 DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=Free2], .MEZOOsortdiv .CATNormalDropDownList option[value=Free2 DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=Free3], .MEZOOsortdiv .CATNormalDropDownList option[value=Free3 DESC]").remove(); 
	$(".MEZOOsortdiv .CATNormalDropDownList option[value=DateCreated], .MEZOOsortdiv .CATNormalDropDownList option[value=DateCreated DESC]").remove(); 



/*moadon form*/
if($(".UDT_Form fieldset.UDT_Field").length!=0){
	$("fieldset.UDT_Field").eq(1).addClass("terms");
	$(".UDT_Default").attr("value", "הרשמה")
}

//homepages sales
if ($(".HomePageContent").length!=0){
	//making the link from inside the sales iframe work
	$(".HomePageContent A").click(function(event){
		event.preventDefault(); 
		var str=$(this).attr("href");
		var newStr=str.split("ProductID")
		newHref="%D7%97%D7%A0%D7%95%D7%AA/tabid/1206/CategoryID/28/List/1/Level/a/ProductID" + newStr[1]
		parent.location.href=newHref;
	})

	
    $(".HomePageContent .MEZOOItemPane TR:first, .HomePageContent .MEZOOcartRow, .HomePageContent .MEZOOsort, .HomePageContent .MEZOOpaging").remove();
    $(".HomePageContent .MEZOOItemPane TR:first").remove();
//    $(".HomePageContent .MEZOOItemPane TR:last").remove(); made into comment because when less than 6 items on sale made last item removed and not just an empty row
    $(".HomePageContent .MEZOOcart, .HomePageContent .MEZOOmoreinfo").remove();

    $(".HomePageContent .ProductListItem A").each(function() {
        varhref = $(this).attr("href");
        $(this).attr("href", varhref.replace("/tabid/641/", "/tabid/1206/"));
    })
}


//changing ok picture
if ($(".MEZOOok").length!=0){
	$(".MEZOOok IMG").each(function(){
		if( $(this).attr("src")=="/images/green-ok.gif"){
			$(this).attr("src", "/portals/laguna/skins/laguna/gfx/green-ok.gif")	
		}
	})
	$(".MEZOOok IMG").delay(500).fadeIn()
}

//changing alert picture, error picture
if ($(".CAT_CartContent").length!=0){
	$(".CAT_CartContent IMG").each(function(){
		if( $(this).attr("src")=="/images/yellow-warning.gif"){
			$(this).attr("src", "/portals/laguna/skins/laguna/gfx/yellow-warning.png")	
		}else if ( $(this).attr("src")=="/images/red-error.gif"){
			$(this).attr("src", "/portals/laguna/skins/laguna/gfx/red-error.png")
		}
	})
	$(".CAT_CartContent IMG").fadeIn()
}


if ($("#tblUserData").length!=0){
	$("#tblUserData IMG").each(function(){
		if( $(this).attr("src")=="/images/required.gif"){
			$(this).attr("src", "/portals/laguna/skins/laguna/gfx/required.gif")	
		}
	})
	$("#tblUserData IMG").delay(500).fadeIn()
}

//sale price list view	
    $(".ProductListItem .MEZOOmoreprice").each(function() {
         $(this).parent().find(".CATSubHead").remove();
	
        if ($(this).find(".CATUnitCost").length != 0) {
	  $(this).parent().css("width", "155px")
            $(this).find(".CATUnitCost").remove();
	$(this).find("SPAN").css("margin", "auto");
            $(this).find(".CATProductListItem, DIV .CATNormalBold").css({ "background": "url(/portals/laguna/skins/laguna/gfx/priceBGnormal.gif) repeat-x scroll right top transparent", "font-size": "12px" });
            $(this).find(".CATProductListItem").next().remove();
            $(this).find(".CATProductListItem").text("מחיר רגיל: " + $(this).find(".CATProductListItem").text());
           // $(this).find(".CATNormalBold:first").css({ "width": "140px"});
$(this).find(".CATNormalBold:first").css({ "font-size": "12px"});
        }
       
    })

//sale price shop homepage
if ($(".MEZOOMiniDashBoard").length!=0){
	$(".MEZOOMiniDashBoard TR:first").remove();
	$(".MEZOOMiniDashBoard  .MEZOOProductPrice").each(function(){

	 if ($(this).find(".CATUnitCost").length != 0) {
 		$(this).find(".CATUnitCost, .CATSubHead").remove();
		$(this).find(".CATProductListItem, DIV .CATNormalBold").css({ "background": "url(/portals/laguna/skins/laguna/gfx/priceBGnormal.gif) repeat-x scroll right top transparent", "font-size": "12px" });
	        $(this).find(".CATProductListItem").next().remove();
		$(this).find(".CATProductListItem").text("מחיר רגיל: " + $(this).find(".CATProductListItem").text()).css("font-size","12px");
		$(this).find(".CATNormalBold:first").css({ "width": "140px",  "font-size":"16px","background": "url(/portals/laguna/skins/laguna/gfx/priceBG.gif) repeat-x scroll right top transparent" });
           
	}else {
	
         $(this).find(".CATProductListItem").text("רק: " + $(this).find(".CATProductListItem").text());
        }
})
}

//sale price card view	
if ($(".HomePageContent .MEZOOcarditem").length==0){
	$(".MEZOOcarditem TD.ProductListItem .MEZOOprice").each(function(){
		$(this).find(".CATSubHead").remove();
	 	if ($(this).find(".CATUnitCost").length != 0) {
	 		$(this).find(".CATUnitCost").remove();
			$(this).find(".CATProductListItem").css({"background": "url(/portals/laguna/skins/laguna/gfx/priceBGnormal.gif) repeat-x scroll right top transparent", "font-size": "12px" });
		        $(this).find(".CATProductListItem").next().remove();
			$(this).find(".CATProductListItem").text("מחיר רגיל: " + $(this).find(".CATProductListItem").text()).css("font-size","12px");
	
           
		}
	})
}

//sale price home page	
if ($(".HomePageContent .MEZOOcarditem").length!=0){

	$(".MEZOOcarditem TD.ProductListItem .MEZOOprice").each(function(){
	 	if ($(this).find(".CATUnitCost").length != 0) {
	 		$(this).find(".CATUnitCost").remove();
		        $(this).find(".CATProductListItem").next().remove();
		   $(this).find(".CATNormalBold").next().remove();
		   
		   $(this).find(".CATNormalBold").text($(this).find(".CATNormalBold").text().replace("מחיר מבצע:",""));
		   
				   
		}
	})
}


//sale price product page

	if ($(".MEZOOproductdetails .CATUnitCost").length != 0) {	
		$(this).find(".CATUnitCost").remove();	
		$(".MEZOOproductactualprice TD").css("background", "none")
		$(".MEZOOproductactualprice TD:first").remove();
		$(".MEZOOproductactualprice .CATProductListItem").text(	"מחיר רגיל: " + $(".MEZOOproductactualprice .CATProductListItem").text()).css("font-weight", "normal");
		$(".MEZOOproductactualprice .CATNormalBold:first").css("font-size","20px");
			$(".MEZOOproductactualprice DIV .CATNormalBold:first").css({"color":"#FFF", "font-size":"16px"});
		
		}

   
    //topMenu-hover
    $('.headerRow li.level-0').hover(
       function() {
           if ($(this).hasClass('Admin') == false) {
               if ($(this).find('ul.level-1').length != 0) {
                   $(this).css('height', '37px');
                   $('li.level-1:eq(0) a', this).css('padding-right', '11px');
                   $('li.level-1:last a', this).css('padding-left', '10px');
               }


               zindex += 1;
               $(this).find('ul.level-1')
                .css({ 'z-index': zindex })
                .removeClass('hide-this').show(); //fadeIn(100);
           }
       },
	function() {
	    $(this).css('height', '35px');
	    var o = $(this);
	    o.find('ul.level-1').addClass('hide-this');
	    o.find('ul.level-1.hide-this').hide(); //fadeOut(70);
	});

    //  דף מצב הרוח

   
    //SHOP

    if ($(".MEZOOItemPane").length != 0) {
        $(".MEZOOprice .CATSubHead").text("רק");
        $(".MEZOOItemPane #tblSortField TD:eq(0), .MEZOOItemPane #tblSortField TD:eq(1), .MEZOOItemPane #tblSortField TD:last ").addClass("stay");
        $(".MEZOOItemPane #tblSortField TD:not(.stay)").remove();
        $(".MEZOOItemPane #tblSortField").css("visibility", "visible");
      //  if ($(".MEZOOcarditem").length == 0 ) {
     //       $("#tblSortField").after("<div class='tblCompare'> " + $(".MEZOOItemPane .MEZOOcompareRow").html() + " " + "</div>");
     //   }
        var BackLink = $("TD.MEZOObacklink A:first").attr("href");
        $("TD.MEZOObacklink").parent().remove();
        $("#AdvCatsBreadCrumbsTable TD").after("<td align='left'> <img src='/DesktopModules/CATALooKStore/Skins/blue/cat_breadcrumb.gif'>&nbsp;<a href='" + BackLink + "' class='CATCommandButton'>חזרה לתוצאות</a></td>")
	
	    pageText=$(".MEZOOpaging .CATPagingTable TD:first").text();
	    pageText=pageText.replace("Page ", "עמוד ");
	    pageText=pageText.replace("of ", "מתוך ");
	    $(".MEZOOpaging .CATPagingTable TD:first").text(pageText).css({"display":"block", "width":"136px"})
	    $(".MEZOOpaging .CATPagingTable TD").eq(1).addClass("paging2").css("width","454px");
	    $(".paging2 SPAN").each(function(){
		    tempText=$(this).text();
		    if (tempText=="First") {
			    tempText=tempText.replace("First", "ראשון")
		    } else if (tempText == "Last") {
			    tempText=tempText.replace("Last", "אחרון")
		    } else if (tempText == "Previous") {
		    tempText = tempText.replace("Previous", "הקודם")
		    } else if (tempText == "Next") {
			    tempText=tempText.replace("Next", "הבא")		    } 
		    $(this).text(tempText);
	    })
	    $(".paging2 A").each(function(){
	        tempText=$(this).text();
	        if (tempText=="First") {
		        tempText=tempText.replace("First", "ראשון")
	        } else if (tempText == "Last") {
		        tempText=tempText.replace("Last", "אחרון")
	        } else if (tempText == "Previous") {
	        tempText = tempText.replace("Previous", "הקודם")
	        } else if (tempText == "Next") {
		        tempText=tempText.replace("Next", "הבא")	        } 				
            $(this).text(tempText);
	    })
	
    }

    $('td.CATRow li.CATMenuLevel1').hover(

       function() {
           // alert("aa");
           zindex += 1;
           $(this).find('ul')
                .css({ 'z-index': zindex })
                .removeClass('hide-this').show();
       },
	function() {


	    var o = $(this);
	    o.find('ul').addClass('hide-this');
	    o.find('ul.hide-this').hide();
	});



    //SHOP category menu
    if ($(".categoryTable").length != 0) {

        $(".categoryTable .CATMenuContainer TABLE").addClass("categoryLinkTable");
        $("#dnn_ctr2171_Menu_catSolPartControl_ctlMenu_divOuterTables").addClass("subCategoryHiddenTablesSpan")
        $(".CATMenuRootArrow IMG").remove();
        $(".categoryTable .CATMenuBG").css("visibility", "visible"); //showing menu again after all changes are made

        //kepping parent menu colored while sub menu shown
        $(".categoryLinkTable .CATMenuItem").hover(function() {
            $(".categoryLinkTable .keepShowing").removeClass("keepShowing");
            $(this).addClass("keepShowing");
        })



        $(".CATSubMenu").hover(function() {
            $(this).addClass("ShowingSub");
        }, function() {
            $(this).removeClass("ShowingSub");
            $(".keepShowing").removeClass("keepShowing");
        })


        $(".CATListBorder").parent().addClass("ProductListItem");
    }

    //gallery
    if ($(".mezoo-basic-gallery-thumbnails A").length != 0) {
        $(".mezoo-basic-gallery-thumbnails A").not(".adminLink").lightBox();
    }


    //footer
    $(".footerRow .logospane LI").last().addClass("last");
    $(".footerRow .logospane LI").first().addClass("first");
    $(".footerRow .footerpane UL").first().addClass("first");
    $(".footerRow .footerpane UL").last().addClass("last");

    //homepage articles
    if ($(".moreNews").length != 0) {
        $(".moreNews").prev().addClass("listItems")
        $(".listItems SPAN").addClass("listItem").next().remove();
        $(".listItems").wrap("<div class='listItemWrapper'>");

        var i = 0;
        $(".listItemWrapper").each(function() {
            i++;
            $(this).parent().addClass("hpArticleList_" + i);
            $(this).parent().addClass("hpArticle");
        })
        $(".hpArticle").prepend("<span class='nextNews'><a href='javascript:void(0)'>הבא<a/></span>");
	$(".contentpane_HP .DNNArticleListContent").css("visibility","visible")
    }

    $(".nextNews").click(function(e) {
        e.preventDefault();
        clearTimeout(mm);
        move();
        clearTimeout(mm2);
        move2();
    })

 

    if (PageName == "home") {
        var slideWidth = 596;
        $("#slideshow").append("<div class='dotsContainer' />")
    } else {
        var slideWidth = 283;
        $("#smallslideshow").append("<div class='dotsContainer' />")
    }
    //home page slider


    var numberOfSlides = $('.slide').length;
    $('#slidesContainer').css('overflow', 'hidden'); // Remove scrollbar in JS
    $('#slideInner').css('width', slideWidth * numberOfSlides);   // Set #slideInner width equal to total width of all slides
    manageControls(0);    // Hide left arrow control on first load
    // $("#slideshow").append("<div class='dotsContainer' />")
    $('.dotsContainer').css('width', 20 * numberOfSlides);
    for (i = 1; i <= $(".slide").length; i = i + 1) {
        if (i == 1)
            $(".dotsContainer").append("<img src='" + skinPath + "gfx/dotCurrent.png' class='dot currentDot' />");
        else
            $(".dotsContainer").append("<img src='" + skinPath + "gfx/dot.png' class='dot'/>");
    }

    //clicking next/prev change position
    $('.control').click(function() {
        clearTimeout(rr);
        currentPosition = $(".currentSlide").index();
        currentPosition = ($(this).attr('id') == 'rightControl') ? currentPosition + 1 : currentPosition - 1;
        manageControls(currentPosition);
        slidemovement();
        return false;
    })

    //clicking dots change position
    $('.dot').click(function() {
        clearTimeout(rr);
        currentPosition = $(this).index()
        manageControls(currentPosition);
        slidemovement();
    })

    $(".listItemWrapper").hover(function() {
        clearTimeout(mm);
        clearTimeout(mm2);
    }, function() {
        setTimeout("move()", 8000);
        setTimeout("move2()", 8000);

    })

    rr = setTimeout("AutoSliding()", 8000);
    mm = setTimeout("move()", 8000);
    mm2 = setTimeout("move2()", 8000);

    if ($(".hpArticleList_1").length != 0) {
        $(".hpArticleList_1 A.moreNews").attr("href", "/דףהבית/מאמרים/חדשות.aspx");
        $(".hpArticleList_2 A.moreNews").attr("href", "/דףהבית/מאמרים/כתבותוסרטים.aspx");
    }

  	$(".pNewsletter .NormalTextBox").focus(function(){
		$(this).val("");
	})
});


//news and articles on homepage
function move() {
    itemheight = $(".hpArticleList_1 .listItem").first().height();
    $(".hpArticleList_1 .listItems").animate({ top: -itemheight }, 2000, function() {
        $(".hpArticleList_1 .listItems").append($(".hpArticleList_1 .listItem").eq(0));
        $(".hpArticleList_1 .listItems").css("top", "0");
        mm = setTimeout("move()", 8000);
    })
}

function move2() {
    itemheight2 = $(".hpArticleList_2 .listItem").first().height();
    $(".hpArticleList_2 .listItems").animate({ top: -itemheight2 }, 2000, function() {
        $(".hpArticleList_2 .listItems").append($(".hpArticleList_2 .listItem").first());
        $(".hpArticleList_2 .listItems").css("top", "0");
        mm2 = setTimeout("move2()", 8000);
    })
}


//home page slider auto start
function AutoSliding() {
    var listItem = $(".currentDot");
    dotLength = ($(".dotsContainer > IMG").length);
    currentPosition = $('.dotsContainer IMG').index(listItem) + 1;
    if (currentPosition == dotLength)
        currentPosition = 0
    manageControls(currentPosition);
    slidemovement();
    rr = setTimeout("AutoSliding()", 8000);
}

function getFlashMovieObject(movieName) { //passing params to flash
    if (window.document[movieName]) //firefox
    {
        return window.document[movieName];
    }

    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else {
        return document.getElementById(movieName);
    }
}


function openLightbox(name) {

    $('.lightbox').hide();

    var arrayPageSize = getPageSize();
    $('.overlay').css({
        opacity: '0',
        height: arrayPageSize[1] + 'px'
    }).show().animate({ opacity: '0.6' });



    var $lightbox = $(name).parent();
    $lightbox.fadeIn();
}

function getPageSize() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}

	var arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function manageControls(position) { //hiding and showing next prev buttons
    if (position == 0) { $('#leftControl').hide() }
    else { $('#leftControl').show() }
    numberOfSlides = $('.slide').length;
    if (position == numberOfSlides - 1) { $('#rightControl').hide() }
    else { $('#rightControl').show() }

    $(".dotsContainer IMG").attr("src", skinPath + "gfx/dot.png").removeClass("currentDot");
    $("#slideInner .slide").removeClass("currentSlide");
    $(".dotsContainer IMG:eq(" + position + ")").attr("src", skinPath + "gfx/dotCurrent.png").addClass("currentDot");
    $("#slideInner .slide:eq(" + position + ")").addClass("currentSlide");
    if ($(".currentSlide DIV").hasClass("flash")) {
        var flashID = $(".currentSlide OBJECT").attr("id");
        var flashMovie = getFlashMovieObject(flashID);
        flashMovie.SetVariable("mytext", "start");
    }
}

function slidemovement() {  //actually moving the slide
    if (PageName == "home") {
        var slideWidth = 596;
        $('#slideshow .slide DIV.cover').css("bottom", "-25px");
    } else {
        var slideWidth = 283;
        $('#smallslideshow .slide DIV.cover').css("bottom", "-25px");
    }

    $('#slideInner').animate({
        'left': slideWidth * (-currentPosition)
    }, 'slow', function() {
        $('.slide DIV.cover').animate({
            'bottom': '0'
        });
    });
}

