//** hover invisible button span search ==========================================
$(function () {
    $(".lien-he-class").hover(
       function () {
           $("#iconsearch").hide(); $("#div_yahoo").show();},
       function () {
           $("#iconsearch").show(); $("#div_yahoo").hide();});
   });
   $(function () {
       $("#div_yahoo").hover(
       function () { $("#div_yahoo").show(); },
       function () { $("#div_yahoo").hide(); });


       $('#display_yahoo').click(function () {
           Popup.show('display_yahoo_list');
           $("#display_yahoo_list").css('margin-top', '30px');
       });

       $('#display_yahoo_bottom').click(function () {
           Popup.show('display_yahoo_list');
           if ($.browser.msie) {
               if ($.browser.version == "6.0") {
                   $("#display_yahoo_list").css('margin', '0px 0px 0px -134px');
               }
               if ($.browser.version == "7.0") {
                   $("#display_yahoo_list").css('margin', '0px 0px 0px -134px');
               }
               if ($.browser.version == "8.0") {
               }
               else
                   $("#display_yahoo_list").css('margin', '449px 0px 0px -134px');

           }
           else {
            $("#display_yahoo_list").css('margin', '449px 0px 0px -134px');
            }
           
       });

   });
   //===========menu

   $(function () {
       $("#hang-thanh-ly").hover(
          function () { $("#hang-thanh-ly").css("background", "#E9E9E9"); $("#hang-thanh-ly a").css("color", "#272727"); },
          function () { $("#hang-thanh-ly").css("background", "none"); $("#hang-thanh-ly a").css("color", "White"); });
       $("#bang-gia").hover(
          function () { $("#bang-gia").css("background", "#E9E9E9"); $("#bang-gia a").css("color", "#272727"); },
          function () { $("#bang-gia").css("background", "none"); $("#bang-gia a").css("color", "White"); });
       $("#download").hover(
          function () { $("#download").css("background", "#E9E9E9"); $("#download a").css("color", "#272727"); },
          function () { $("#download").css("background", "none"); $("#download a").css("color", "White"); });
       $("#home").hover(
          function () { $("#home").css("background", "#E9E9E9"); $("#home a").css("color", "#272727"); },
          function () { $("#home").css("background", "none"); $("#home a").css("color", "White"); });
       $("#thanh-toan").hover(
          function () { $("#thanh-toan").css("background", "#E9E9E9"); $("#thanh-toan a").css("color", "#272727"); },
          function () { $("#thanh-toan").css("background", "none"); $("#thanh-toan a").css("color", "White"); });
          
   });
   

   $(function () {
       $("li.products").hover(
          function () { $(".lof-navigator-outer2").hide(); $(".d-product").show(); $(".products").css("background", "#E9E9E9"); $(".products a").css("color", "#272727"); $("#lofslidecontent45").hide(); },
          function () { $(".lof-navigator-outer2").show(); $(".d-product").hide(); $(".products").css("background", "none"); $(".products a").css("color", "White"); $("#lofslidecontent45").show(); });

       $("li.services").hover(
          function () { $(".d-service").show(); $(".services").css("background", "#E9E9E9"); $(".services a").css("color", "#272727"); $("#lofslidecontent45").hide(); },
          function () { $(".d-service").hide(); $(".services").css("background", "none"); $(".services a").css("color", "White"); $("#lofslidecontent45").show(); });

       $(".d-product").hover(
          function () { $(".lof-navigator-outer2").hide(); $(".d-product").show(); $(".products").css("background", "#E9E9E9"); $(".products a").css("color", "#272727"); $("#lofslidecontent45").hide(); },
          function () { $(".lof-navigator-outer2").show(); $(".d-product").hide(); $(".products").css("background", "none"); $(".products a").css("color", "White"); $("#lofslidecontent45").show(); });

       $(".d-service").hover(
          function () { $(".d-service").show(); $(".services").css("background", "#E9E9E9"); $(".services a").css("color", "#272727"); $("#lofslidecontent45").hide(); },
          function () { $(".d-service").hide(); $(".services").css("background", "none"); $(".services a").css("color", "White"); $("#lofslidecontent45").show(); });
   });


   $(document).ready(function () {
       $("#body_form").css("-moz-box-shadow", "0px 0px 30px #202020");
   });



//** click span close ==========================================
function spanclickclose() {
    $(".yahoo_avertise_left").slideUp();
}
function spanclickclose_music() {
    $(".music_christmas").slideUp();
}
function spanclickclose_display_yahoo() {
    $(".display-yahoo-list").slideUp();
}

//** click span in seach ==========================================
function spanclick() {
    document.getElementById('btnSearch').click();
    return false;
}

//** detect display monitor ==========================================
window.onload = function aa() {
    if (screen.width >= 1024) {
        $("#display_yahoo").hide();
    }
    else {
        $(".yahoo_avertise_left").hide();
    }
}

//** check browser ==========================================
window.onload = function aa() {
    var textstyle = '';

    if ($.browser.msie) {
        if ($.browser.version == "6.0") {
            $(document).ready(function () {
                $(".position_btn_m").css("margin", "0px 0px 0px 35px");
                $(".music_christmas").css("position", "fixed");
                $(".music_christmas").css("margin", "-50px 0px 0px 500px");

                $(".yahoo_avertise_left").css("position", "absolute");
                $(".yahoo_avertise_left").css("top", "0px");
            });
            textstyle += ".position_btn_m{margin-top:-1px; margin-left:-35px;position:absolute;}";
            textstyle += ".yahoo_avertise_left{position:absolute;top:0px;}";
        }
        else
            textstyle += ".img_menu_layout_product {margin-top:110px;}.img_menu_layout_service {margin:85px 0px 0px -150px;} .position_btn_m{margin:0px 0px 0px 36px;}";

    }
    else {
        textstyle += ".content_layout {padding-right: 0px;} .avertise_right{width: 309px;height: 250px;}";
        textstyle += "#download a, #bang-gia a, #hang-thanh-ly a, #home a{color:White;}";
    }

    if ($.browser.mozilla) {
        if ($.browser.version < "3.6.24") {
            textstyle += ".position_btn_c{margin:-14px 0px 0px 108px;} .content_layout {padding-right: 0px;} .avertise_right{width: 309px;height: 250px;}";
            textstyle += ".img_menu_layout_product {margin: 170px 0px 0px 130px;}";
            textstyle += ".img_menu_layout_service {margin: 116px 0 0 820px;}";
            textstyle += "ul.lof-navigator li{margin-top:-2px;padding-bottom:2px;}ul.lof-navigator li span {line-height: 0;margin: 4px 0 0 -3px;position: absolute;}";
        }
        else {
            textstyle += "#lofslidecontent45{width: 337px;}.position_btn_m {margin:0px 0px 0px 39px;} .iframe-w-h {width: 656px;}ul.lof-navigator li span {line-height: 0;margin: 4px 0 0 -3px;position: absolute;}";
            textstyle += ".t-info{width: 338px;line-height: 1.6;}";
        }
    }
    if ($.browser.opera) {
        textstyle += ".position_btn_c{margin:-14px 0px 0px 108px;}#li_search, #li_search:hover {padding-left: 24px;} .content_layout {padding-right: 0px;} .avertise_right{width: 309px;height: 250px;}";
        textstyle += ".img_menu_layout_product {margin: 113px 0px 0px 269px;}";
        textstyle += ".img_menu_layout_service {margin: 79px 0 0 836px;}";
        textstyle += ".widthheight1 {margin-right: -270px;}";
    }

    if ($.browser.chrome) {
        version = userAgent.substring(0, userAgent.indexOf('.'));
        if (version >= 15)
            textstyle += "#list_yahoo {margin-left:-73px;}";
    }

    if ($.browser.safari) {

        textstyle += "#list_yahoo {margin-left:-73px;}.content_layout {padding-right: 0px;} #lofslidecontent45{width: 337px;}";
        textstyle += ".position_btn_m {margin: -0.7px 0px 0px 39px;}";
    }
    try { var style = document.getElementById("style").appendChild(document.createTextNode(textstyle)); } catch (e) { }

}


// fixed coontacYahoo ================================================================================

$(function () {
    var msie6 = $.browser == 'msie' && $.browser.version < 7;

    if (!msie6) {
        var top_ya = $('.yahoo_avertise_left').offset().top - parseFloat($('.yahoo_avertise_left').css('margin-top').replace(/auto/, 0));
        $(window).scroll(function (event) {
            var y_ya = $(this).scrollTop();
            if (y_ya >= top_ya) {
                $('.yahoo_avertise_left').addClass('fixed');
            } else {
                $('.yahoo_avertise_left').removeClass('fixed');
            }
        });

    }
});

//** Hover menu top =========================================
//$(document).ready(function () {
//    var toggle = function (direction, display) {        return function () {            var self = this;
//            var ul = $("ul", this);
//            if (ul.css("display") == display && !self["block" + direction]) {
//                self["block" + direction] = true;
//               ul["slide" + direction]("slow", function () {
//                   self["block" + direction] = false;
//                });
//            }
//       };
//    }
//    $("li.right-sub").hover(toggle("Down", "none"), toggle("Up", "block"));
//    $("li.right-sub ul").hide();
//});

//** change img background kho-may-cu =========================================
//$(document).ready(function () {
//    var pageURL = document.location.href
//    var MyArray = pageURL.split("/")
//    var BaseURL = MyArray[3]
//    if (BaseURL == "kho-may-cu") {
//        var idimg = document.getElementById("kho-may-cu");
//        if (idimg != null)
//            idimg.src = "templates/vn_default/images/but_active_10.jpg";
//    }
//});

//** Hover menu top =========================================




var scrolltotop={
	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
	setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
	controlHTML: '<div class="button_scroll_top"></div>', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
	controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
	anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		if (!this.cssfixedsupport) //if control is positioned using JavaScript
			this.$control.css({opacity:0}) //hide control immediately after clicking it
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
			dest=jQuery('#'+dest).offset().top
		else
			dest=0
		this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var $window=jQuery(window)
		var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
		var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
		this.$control.css({left:controlx+'px', top:controly+'px'})
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},
	
	init:function(){
		jQuery(document).ready(function($){
			var mainobj=scrolltotop
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
			mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
				.attr({title:'Scroll Back to Top'})
				.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			$('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
				mainobj.scrollup()
				return false
			})
			$(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}

scrolltotop.init()
