/*$(function(){
	var _ua = (function(){
		return {
			ltIE6:typeof window.addEventListener == "undefined" && typeof document.documentElement.style.maxHeight == "undefined",
			ltIE7:typeof window.addEventListener == "undefined" && typeof document.querySelectorAll == "undefined",
			ltIE8:typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined",
			ie:document.uniqueID,
			firefox:window.globalStorage,
			opera:window.opera,
			webkit:!document.uniqueID && !window.opera && !window.globalStorage && window.localStorage,
			mobile:/android|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())
		}
	})();

	if(_ua.ltIE6){
		DD_belatedPNG.fix('img');
	}

});*/


/*
---------------------------------------------------------
	smartRollover
---------------------------------------------------------
*/
/*
function smartRollover() {
  if(document.getElementsByTagName) {
    var images = document.getElementsByTagName("img");
    var preImages = new Array();
      for(var i=0; i < images.length; i++) {
        if(images[i].getAttribute("src").match("_off.")) {
        var preImage = new Image();
        preImage.src =
        images[i].getAttribute("src").replace("_off.", "_on.");
        preImages.push(preImage);
        images[i].onmouseover = function() {
          this.setAttribute("src",
          this.getAttribute("src").replace("_off.", "_on."));
        }
        images[i].onmouseout = function() {
          this.setAttribute("src",
          this.getAttribute("src").replace("_on.", "_off."));
        }
      }
    }
  }
}*/

/*
---------------------------------------------------------
	smartRollover
---------------------------------------------------------
*/


function smartRollover(){
    if(document.getElementsByTagName) {
        var elements = [];

        var images = document.getElementsByTagName("img");
        var length = images.length;
        for (var i = 0; i < length; i++) {
            elements[i] = images[i];
        }

        var inputs = document.getElementsByTagName("input");
        length = inputs.length;
        for (var j = 0; j < length; j++) {
            if (inputs[j].type == "image") {
                elements[i++] = inputs[j];
            }
        }
        
        length = elements.length;
        var preImages = [];
        for(i = 0; i < length; i++) {
            if(elements[i].getAttribute("src").match("_off.")) {
                var preImage = new Image();
                elements.src =
                    elements[i].getAttribute("src").replace("_off.", "_on.");
                preImages.push(preImage);
                elements[i].onmouseover = function() {
                    this.setAttribute("src",
                    this.getAttribute("src").replace("_off.", "_on."));
                }
                elements[i].onmouseout = function() {
                    this.setAttribute("src",
                    this.getAttribute("src").replace("_on.", "_off."));
                }
            }
        }
    }
};
/*
---------------------------------------------------------
	areaHover
---------------------------------------------------------
*/
function areaHover(){
	var linkElement = $("body#brandList #mainContents .section a,#newsIndex a,#brandNews li a,#brandItem a,#sideContents #brandMovies a,#sideContents #brandCatalog a,#blogList .blogIndex a,#ahInfo a,#blogEntry .section a").not("li.link a");
	linkElement.mouseover(function(){
		var change = $("a[href=" + $(this).attr('href') + "]").not("li.link a,.aside a,.brandLink a,#news #sideContents #blogEntry .section a,#blogCalendar a");
		change.not("a:has(img)").not("#brandBlog #mainContents h2 a").addClass("act");
		change.find("img").not("li.link a img").each(function(i,e){
			e.src = e.src.replace(/_off\./ , "_on."); 
		}); 
	});
	linkElement.mouseout(function(){
		var change = $("a[href=" + $(this).attr('href') + "]").not("li.link a,.aside a,.brandLink a,#news #sideContents #blogEntry .section a,#blogCalendar a");
		change.not("a:has(img)").not("#brandBlog #mainContents h2 a").removeClass("act");
		change.find("img").not("li.link a img").each(function(i,e){
			e.src = e.src.replace(/_on\./ , "_off."); 
		}); 
	});
};
/*
---------------------------------------------------------
	areaHoverR
---------------------------------------------------------
*/
function areaHoverR(){
	var linkElement = $("body#recruit #seniorList a, body#recruit .careerType a");
	linkElement.mouseover(function(){
		var change = $("a[href=" + $(this).attr('href') + "]");
		change.css({"color":"#b39b7f", "text-decoration":"underline"});
		change.find("img").each(function(i,e){
			e.src = e.src.replace(/_off\./ , "_on."); 
		}); 
	});
	linkElement.mouseout(function(){
		var change = $("a[href=" + $(this).attr('href') + "]");
		change.css({"color":"#000", "text-decoration":"none"});
		change.find("img").each(function(i,e){
			e.src = e.src.replace(/_on\./ , "_off."); 
		}); 
	});
};

/*
---------------------------------------------------------
	imgMaxWidth
---------------------------------------------------------
*/
function imgMaxWidth(){
	var img = $("body#brandBlog #mainContents .article .inner img,body#news #mainContents .inner img");
	img.each(function(){
		var imgWidth = $(this).width();
		if( imgWidth > 548 ) {
			$(this).css({"width":"548px","height":"auto"});
		}
	});
};


/*
---------------------------------------------------------
	newPost include for brandPage
---------------------------------------------------------
*/

$(function(){
	var bodyID = $('body').attr('id');
	var bodyClass = $('body').attr('class');
	var beSize = $('#blogEntry').size();
	if(bodyID == 'brandTop' && beSize != 0){
		var loc = location.href.split('/');
		var dir = (loc[loc.length -2]);
		var dir1 = (loc[loc.length -3]);
		if(dir == 'designworks'){
			var urlStr = '/official-blog/' + dir + '-' + dir1 + '/newPost.xml';
		}else if(dir == 'revisitation'){
			var urlStr = '/official-blog/rouge-vif-la-cle/newPost.xml';
		}else if(dir == 'bexist' || dir == 'recency-of-mine'){
			var urlStr = '/official-blog/abahouse-lastword/newPost.xml';
		}else{
			var urlStr = '/official-blog/' + dir + '/newPost.xml';
		}
		$('#sideContents').find('#blogEntry').find('dl').find('dt,dd').remove();
		$.ajax({
			url: urlStr,
			async: true,
			cache: false,
			dataType: 'xml',
			success: function(xml){
				$(xml).find('entry').each(function(){
					var img = $(this).find('img').attr('src');
					var title = $(this).find('title').text();
					var date = $(this).find('date').text();
					var url = $(this).find('link').attr('href');
					$('#sideContents').find('#blogEntry').find('dl').append('<dt class="img"><a href="' + url + '"><img src="' + img + '" alt="' + title + '" /></a></dt><dd class="date">' + date + '</dd><dd><a href="' + url + '">' + title + '</a></dd>');
				});
			},
			complete: function(xml){
			}
		})
	};
	if(bodyID == 'blogList'){
		$('#officialBlog').find('.blogIndex').load('/official-blog/blog_index.html');
	}

	var _ua = (function(){
		return {
			ltIE6:typeof window.addEventListener == "undefined" && typeof document.documentElement.style.maxHeight == "undefined",
			ltIE7:typeof window.addEventListener == "undefined" && typeof document.querySelectorAll == "undefined",
			ltIE8:typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined",
			ie:document.uniqueID,
			firefox:window.globalStorage,
			opera:window.opera,
			webkit:!document.uniqueID && !window.opera && !window.globalStorage && window.localStorage,
			mobile:/android|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())
		}
	})();

	if(_ua.ltIE6){
		DD_belatedPNG.fix('img,#header #siteIdentity a,#header ul li a,#mainContents .article .heading h2,#mainContents .article .heading .banner,#mainContents .article .heading .link a,.atscheltaLink a,#ahInfo span,#footer #copyright,#footer #copyright span,#footer ul li a,#ahInfo li a');
	}

	if(bodyID == 'brandTop'){
		if(bodyClass == 'women abahouse-devinette'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_women04.png" width="176" height="234" class="frame" />');
		}
		if(bodyClass == 'women rouge-vif-la-cle'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_women05.png" width="176" height="234" class="frame" />');
		}
		if(bodyClass == 'women women-5351-pour-les-femmes'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_women03.png" width="176" height="234" class="frame" />');
		}
		if(bodyClass == 'accessory au-bannister'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_accessory04.png" width="176" height="234" class="frame" />');
		}
		if(bodyClass == 'accessory piche-abahouse'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_accessory04.png" width="176" height="234" class="frame" />');
		}
		if(bodyClass == 'accessory grappe-bannister'){
			$('#brandItem').find('p.img img').parent().append('<img src="/cmn/img/frame_accessory05.png" width="176" height="234" class="frame" />');
		}
	}

});



/*
---------------------------------------------------------
	addLoadEvent
---------------------------------------------------------
*/
function addOnLoadEvent(func) {
	if (window.attachEvent){
		window.attachEvent('onload', func);
	}
	else {
		window.addEventListener('load', func, false);
	}
}
addOnLoadEvent(smartRollover);
addOnLoadEvent(areaHover);
addOnLoadEvent(areaHoverR);
addOnLoadEvent(imgMaxWidth);
;
addOnLoadEvent(imgMaxWidth);

