

$(document).ready(function() {

    //alert('here');
    $(".FormButton").hover(
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
	  },
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_on", "_off"));
	  }
	);
    /*you can apply this class to image buttons so they will have rollover effections*/
    $(".ImageButton").hover(
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
	  },
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_on", "_off"));
	  }
	);

    /*Main Nav*/
    $("ul#menuElem li a img").hover(
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
	  },
	  function() {
	      $(this).attr("src", $(this).attr("src").replace("_on", "_off"));
	  }
	);

    /*any pages use Tab menu layout: Company, Resources etc. */
    $("ul.tabs").tabs("> .pane");
	 //$("ul.tabs").tabs("div.pane");
    //$("#accordion").tabs("#accordion div.pane", {tabs: 'h2', effect: 'slide', initialIndex: null});

    /*$('.readMore').toggle(function() {
    $('.morepane').slideDown('slow');
    }, function() {
    $('.morepane').slideUp('slow');;
    });

	$("div.bioBlock").each(function() {
    var parentElement = $(this);
    $(this).find(".readMore").toggle(function() {
    alert($(parentElement).find(".morepane").attr('class'));									
    $(parentElement).find(".morepane").fadeIn('slow');
    $(this).html("Close");
    $(this).addClass("btnClose");
    }, function() {
    alert('2');
    $(parentElement).find(".morepane").fadeOut('slow');
    $(this).html("Read More");
    $(this).removeClass("btnClose");
    });
    });*/



    /* News & Events */
    if (0 < document.location.href.toLowerCase().lastIndexOf('newsevents.aspx#tabs1')) {
        /*alert('newsevents.aspx#tabs1');
        $("#tabs1").show();
        $("#tabs2").hide();
        $("li#tabNews a").addClass("current");
        $("li#tabEvents a").removeClass("current");*/

    } else if (0 < document.location.href.toLowerCase().lastIndexOf('newsevents.aspx#tabs2')) {
        /*alert('newsevents.aspx#tabs2');
        $("#tabs2").show();
        $("#tabs1").hide();
        $("li#tabEvents a").addClass("current");
        $("li#tabNews a").removeClass("current");*/
    } else if (0 < document.location.href.toLowerCase().lastIndexOf("/newsevents/news/")) {
        /*alert('/newsevents/news/');*/
        $("#tabs1").show();
        $("#tabs2").hide();
        $("li#tabNews a").addClass("current");
        $("li#tabEvents a").removeClass("current");
    } else if (0 < document.location.href.toLowerCase().lastIndexOf("/newsevents/events/")) {
        /*alert('/newsevents/events/');*/
        $("#tabs1").hide();
        $("#tabs2").show();
        $("li#tabEvents a").addClass("current");
        $("li#tabNews a").removeClass("current");
    } else if (0 < document.location.href.toLowerCase().lastIndexOf('/newsevents')) {
        /*alert('/newsevents');
        $("#tabs1").show();*/
        $("#tabs2").hide();
        /*$("li#tabNews a").addClass("current");
        $("li#tabEvents a").removeClass("current");*/
    }

    $("li#tabNews a").click(function() {
        /*$("li#tabNews a").attr('href') = '/newsevents.aspx#tabs1';	
        window.location='/newsevents.aspx#tabs1';
        //alert($("li#tabNews a").attr('href'));*/
        $("#tabs1").show();
        $("#tabs2").hide();
        $("li#tabNews a").addClass("current");
        $("li#tabEvents a").removeClass("current");
    });

    $("li#tabEvents a").click(function() {
        /*$("li#tabEvents a").attr('href') = '/newsevents.aspx#tabs2';
        window.location='/newsevents.aspx#tabs2';
        //alert($("li#tabEvents a").attr('href'));*/
        $("#tabs2").show();
        $("#tabs1").hide();
        $("li#tabEvents a").addClass("current");
        $("li#tabNews a").removeClass("current");
    });
	
	$("li#tabNews a").click(function() {
        //alert('news');
        $("#newsCTA").show();
        $("#eventsCTA").hide();
    });
    $("li#tabEvents a").click(function() {
        //alert('events');
        $("#newsCTA").hide();
        $("#eventsCTA").show();
    });
    /*end News & Events*/

    /* Products & Services */
    $("li#tabJF a").click(function() {
        //alert('JF');
        $("#ctaDynamicServicesBrochure").hide();
        $("#ctaJustFoodBrochure").show();
        $("#ctaEquipSoftBrochure").hide();
    });
    $("li#tabEQ a").click(function() {
        //alert('EQ');
        $("#ctaDynamicServicesBrochure").hide();
        $("#ctaJustFoodBrochure").hide();
        $("#ctaEquipSoftBrochure").show();
    });
    $("li#tabSolutions a").click(function() {
        //alert('tabSolutions');
        $("#ctaDynamicServicesBrochure").show();
        $("#ctaJustFoodBrochure").hide();
        $("#ctaEquipSoftBrochure").hide();
    });
	
	if (0 < document.location.href.toLowerCase().lastIndexOf('productservicejf')) {
		//select Productions & Services (JustfoodERP tab)		
		//$('#productionservicetabs').tabs("initialIndex",1);
		 $('#productionservicetabs').tabs("> .pane", {
			initialIndex: 1								  
		 });
	}
	if (0 < document.location.href.toLowerCase().lastIndexOf('productservicees')) {
		//select Productions & Services (JustfoodERP tab)		
		//$('#productionservicetabs').tabs("initialIndex",1);
		 $('#productionservicetabs').tabs("> .pane", {
			initialIndex: 2								  
		 });
	}
    /* Products & Services */

    /* Resources check cookies */
    $("a.checkCookies").click(function() {
        //alert(($.cookie('ResourcesRegister') == null));
        if (0 < document.location.href.toLowerCase().lastIndexOf('/resources')) {
            //alert(this.href);
            $.cookie('DemoPage', '2571d03a-71af-462c-a424-3300725d2373', { path: '/' });
            $.cookie('DemoVideo', '', { path: '/' });
            $.cookie('RegisterFor', this.href, { path: '/' });
            //alert($.cookie('RegisterFor'));
            /*$("#tabs-1 a").click(function () { 
            $.cookie('DemoPage', '244ec0ad-e920-4087-9596-37287c0b2ad2', {path: '/'});
            $.cookie('DemoVideo', '#tabs-1', {path: '/'});		
            });
            $("#tabs-2 a").click(function () { 
            $.cookie('DemoPage', '244ec0ad-e920-4087-9596-37287c0b2ad2', {path: '/'});
            $.cookie('DemoVideo', '#tabs-2', {path: '/'});
            });
            $("#tabs-3 a").click(function () { 
            //alert('hi');
            $.cookie('DemoPage', '244ec0ad-e920-4087-9596-37287c0b2ad2', {path: '/'});
            $.cookie('DemoVideo', '#tabs-3', {path: '/'});
            });*/
        }

        if (0 < document.location.href.toLowerCase().lastIndexOf('/dsg')) {
	    $.cookie('DemoPage', 'de27d61b-34a6-4d51-958d-d4df4d209b8f', { path: '/' });
            $.cookie('DemoVideo', '', { path: '/' });
            $.cookie('RegisterFor', this.href, { path: '/' });

	}

        if ($.cookie('ResourcesRegister')) {
            //alert('Has registed.');
        } else {
            this.href = '/Resources/Registration.aspx';
            this.target = '_self';
        }
    });

    if ($.cookie('RegisterFor') && $('.HiddenTextBoxField')) {
        $(".HiddenTextBoxField").attr("value", $.cookie('RegisterFor'));
        //alert($(".HiddenTextBoxField").attr("value"));
    }

    function getCookie(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return ""
    }

    function setCookie(c_name, value, expiredays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());
    }

    function checkCookie() {
        username = getCookie('username');
        if (username != null && username != "") {
            //alert('Welcome again ' + username + '!');
        }
        else {
            username = prompt('Please enter your name:', "");
            if (username != null && username != "") {
                setCookie('username', username, 365);
            }
        }
    }
    /* end Resources check cookies */



/*Bing Search*/
	if ($('#WLSearchBoxButton')){
		$('#WLSearchBoxButton').click(function(){
			constructBingSearchString();			   
		});
	}
	
	$(function(){
		$('#WLSearchBoxInput').keydown(function(e){
			if (e.keyCode == 13) {
				constructBingSearchString();
				return false;
			}
		});
	});
	
	function constructBingSearchString() {
		var formTarget = "http://www.bing.com/search?go=&qs=n&sk=&sc=5-11"; // http://www.bing.com/search?q=tools&go=&form=QBLH&qs=n&sk=&sc=5-11&q1=site:equip-soft.com
		if ($('#WLSearchBoxInput').val() != '') {
			formTarget = formTarget + '&q=' + $('#WLSearchBoxInput').val(); // keyword field
		}
		if ($('.WLSearchBoxFORM').val() != '') {
			formTarget = formTarget + '&FORM=' + $('.WLSearchBoxFORM').val();
		}
		if ($('.WLSearchBoxq1').val() != '') {
			formTarget = formTarget + '&q1=' + $('.WLSearchBoxq1').val(); // domain of your site
		}
		//alert(formTarget);
		window.open(formTarget,'newpage',''); // 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'			
	
	}



});
