/** 
#  * Copyright (c) 2008 Pasyuk Sergey (www.codeasily.com) 
#  * Licensed under the MIT License: 
#  * http://www.opensource.org/licenses/mit-license.php 
#  *  
#  * Splits a <ul>/<ol>-list into equal-sized columns. 
#  *  
#  * Requirements:  
#  * <ul> 
#  * <li>"ul" or "ol" element must be styled with margin</li> 
#  * </ul> 
#  *  
#  * @see http://www.codeasily.com/jquery/multi-column-list-with-jquery 
#  */  
jQuery.fn.makeacolumnlists = function(settings){
settings = jQuery.extend({
cols: 2,// set number of columns
colWidth: 0,// set width for each column or leave 0 for auto width
equalHeight: false, // can be false, 'ul', 'ol', 'li'
startN: 1// first number on your ordered list
}, settings);

if(jQuery('> li', this)) {
this.each(function(y) {
var y=jQuery('.li_container').size(),
    height = 0, 
        maxHeight = 0,
t = jQuery(this),
classN = t.attr('class'),
listsize = jQuery('> li', this).size(),
percol = Math.ceil(listsize/settings.cols),
contW = t.width(),
bl = ( isNaN(parseInt(t.css('borderLeftWidth'),10)) ? 0 : parseInt(t.css('borderLeftWidth'),10) ),
br = ( isNaN(parseInt(t.css('borderRightWidth'),10)) ? 0 : parseInt(t.css('borderRightWidth'),10) ),
pl = parseInt(t.css('paddingLeft'),10),
pr = parseInt(t.css('paddingRight'),10),
ml = parseInt(t.css('marginLeft'),10),
mr = parseInt(t.css('marginRight'),10),
col_Width = Math.floor((contW - (settings.cols-1)*(bl+br+pl+pr+ml+mr))/settings.cols);
if (settings.colWidth) {
col_Width = settings.colWidth; 
}
var colnum=1,
percol2=percol;
jQuery(this).addClass('li_cont1').wrap('<div id="li_container' + (++y) + '" class="li_container"></div>');
for (var i=0; i<=listsize; i++) {
if(i>=percol2) { percol2+=percol; colnum++; }
var eq = jQuery('> li:eq('+i+')',this);
eq.addClass('li_col'+ colnum);
if(jQuery(this).is('ol')){eq.attr('value', ''+(i+settings.startN))+'';}
}
jQuery(this).css({cssFloat:'left', width:''+col_Width+'px'});
for (colnum=2; colnum<=settings.cols; colnum++) {
if(jQuery(this).is('ol')) {
jQuery('li.li_col'+ colnum, this).appendTo('#li_container' + y).wrapAll('<ol class="li_cont'+colnum +' ' + classN + '" style="float:left; width: '+col_Width+'px;"></ol>');
} else {
jQuery('li.li_col'+ colnum, this).appendTo('#li_container' + y).wrapAll('<ul class="li_cont'+colnum +' ' + classN + '" style="float:left; width: '+col_Width+'px;"></ul>');
}
}
if (settings.equalHeight=='li') {
for (colnum=1; colnum<=settings.cols; colnum++) {
    jQuery('#li_container'+ y +' li').each(function() {
        var e = jQuery(this);
        var border_top = ( isNaN(parseInt(e.css('borderTopWidth'),10)) ? 0 : parseInt(e.css('borderTopWidth'),10) );
        var border_bottom = ( isNaN(parseInt(e.css('borderBottomWidth'),10)) ? 0 : parseInt(e.css('borderBottomWidth'),10) );
        height = e.height() + parseInt(e.css('paddingTop'), 10) + parseInt(e.css('paddingBottom'), 10) + border_top + border_bottom;
        maxHeight = (height > maxHeight) ? height : maxHeight;
    });
}
for (colnum=1; colnum<=settings.cols; colnum++) {
var eh = jQuery('#li_container'+ y +' li');
        var border_top = ( isNaN(parseInt(eh.css('borderTopWidth'),10)) ? 0 : parseInt(eh.css('borderTopWidth'),10) );
        var border_bottom = ( isNaN(parseInt(eh.css('borderBottomWidth'),10)) ? 0 : parseInt(eh.css('borderBottomWidth'),10) );
mh = maxHeight - (parseInt(eh.css('paddingTop'), 10) + parseInt(eh.css('paddingBottom'), 10) + border_top + border_bottom );
        eh.height(mh);
}
} else 
if (settings.equalHeight=='ul' || settings.equalHeight=='ol') {
for (colnum=1; colnum<=settings.cols; colnum++) {
    jQuery('#li_container'+ y +' .li_cont'+colnum).each(function() {
        var e = jQuery(this);
        var border_top = ( isNaN(parseInt(e.css('borderTopWidth'),10)) ? 0 : parseInt(e.css('borderTopWidth'),10) );
        var border_bottom = ( isNaN(parseInt(e.css('borderBottomWidth'),10)) ? 0 : parseInt(e.css('borderBottomWidth'),10) );
        height = e.height() + parseInt(e.css('paddingTop'), 10) + parseInt(e.css('paddingBottom'), 10) + border_top + border_bottom;
        maxHeight = (height > maxHeight) ? height : maxHeight;
    });
}
for (colnum=1; colnum<=settings.cols; colnum++) {
var eh = jQuery('#li_container'+ y +' .li_cont'+colnum);
        var border_top = ( isNaN(parseInt(eh.css('borderTopWidth'),10)) ? 0 : parseInt(eh.css('borderTopWidth'),10) );
        var border_bottom = ( isNaN(parseInt(eh.css('borderBottomWidth'),10)) ? 0 : parseInt(eh.css('borderBottomWidth'),10) );
mh = maxHeight - (parseInt(eh.css('paddingTop'), 10) + parseInt(eh.css('paddingBottom'), 10) + border_top + border_bottom );
        eh.height(mh);
}
}
    jQuery('#li_container' + y).append('<div style="clear:both; overflow:hidden; height:0px;"></div>');
});
}
}

jQuery.fn.uncolumnlists = function(){
jQuery('.li_cont1').each(function(i) {
var onecolSize = jQuery('#li_container' + (++i) + ' .li_cont1 > li').size();
if(jQuery('#li_container' + i + ' .li_cont1').is('ul')) {
jQuery('#li_container' + i + ' > ul > li').appendTo('#li_container' + i + ' ul:first');
for (var j=1; j<=onecolSize; j++) {
jQuery('#li_container' + i + ' ul:first li').removeAttr('class').removeAttr('style');
}
jQuery('#li_container' + i + ' ul:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container' + i);
} else {
jQuery('#li_container' + i + ' > ol > li').appendTo('#li_container' + i + ' ol:first');
for (var j=1; j<=onecolSize; j++) {
jQuery('#li_container' + i + ' ol:first li').removeAttr('class').removeAttr('style');
}
jQuery('#li_container' + i + ' ol:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container' + i);
}
jQuery('#li_container' + i).remove();
});
}

$(function() {

Shadowbox.init({
players: 'html'
});
$('body').append('<div id=\"OlBrandlist\"><div id=\"OlBrandlistIn\"><p class=\"mb15\"><img src=\"/common/imgs/base/h-ol-brandlist.gif\" alt=\"ブランドリサイト一覧\"></p><ul class=\"OlBrandlist\"></ul></div></div>');

//----------------------------------------------------------------------------------------------------
var PATH_XML = "/common/js/proxy.php?url=http://www.united-arrows.co.jp/brandlist.xml";
//var PATH_XML = "/brandlist.xml";


//----------------------------------------------------------------------------------------------------
var _$brandlist = $("#OlBrandlist");
var _$brandlist_ul = $("ul", _$brandlist);

var _$showBtn = $("#hNav .BRANDLIST a");
var _$closeBtn = $("#OlCloseBtn");

var _isLoaded = false;
var _isOpen = false;

//----------------------------------------------------------------------------------------------------

function init() {
_$showBtn.click(showBtnClicked);
//_$closeBtn.click(closeBtnClicked);

startLoad();
}

function startLoad() {
$.ajax({
type: "GET",
dataType: "xml",
cache: false,
url: PATH_XML,
success: loadCompHdl,
error: erroHdl
});
}

var loadCompHdl = function(data) {
var html = "";
$(data).find("brand").each(function(){
var $this = $(this);
var name = $this.find("name").text();
var image = $this.find("image").text();
var logoname = $this.find("logoname").text();
var link_url = $this.find("link_url").text();
var link_target = $this.find("link_target").text();
html += '<li><a href="'+link_url+'"><span class="logo"><img src="'+image+'" alt="'+name+'"/></span><img src="'+logoname+'" alt="'+name+'"></a></li>'
});
_$brandlist_ul.html(html);
_isLoaded = true;
};
var erroHdl = function() {
};
function showBtnClicked() {
if(!_isLoaded) return false;
//
if(_isOpen) closeBox();
else openBox();
//
return false;
}
function closeBtnClicked() {
closeBox();
return false;
}

var $windowW;
var $posLss;
var $sbH;

var $IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;

function setSs(){
  if($IE6){
$windowW = $(window).width();
$posLss = ($windowW - 730) / 2;
$posLss = $posLss + 'px';
$('#sb-wrapper')
.css('width','730px')
.css('left',$posLss);
$sbH = $('#sb-container').height();
$('#sb-overlay').height($sbH);
}
}

var olPosTop;
var appendhtml;
var appendhtmlheight;
var appendheight;
function openBox() {
//if(_isOpen) return;
appendhtml = _$brandlist.html();
_$brandlist.remove();
Shadowbox.open({
      content:    appendhtml,
      player:     "html",
      width:      730,
      height:      580,
      options: {
        onFinish:function(){
$.autoEnablePNG();
        setSs();
//$('.OlBrandlist').makeacolumnlists({cols: 2, colWidth: 335, equalHeight: false, startN: 1});
$('.OlBrandlist li:nth-child(1)').addClass('firstline');
$('.OlBrandlist li:nth-child(2)').addClass('firstline');
//$('#OlBrandlist img').enablePNG();

$('#li_container2').each(function(){
var $thismainArea = $(this);
var $logolistnum = $thismainArea.find('li').size();
if(14 < $logolistnum && $logolistnum < 17){
$thismainArea.find('li').each(function(){
$(this)
.find('a')
.css('padding-top','18px')
.css('padding-bottom','18px')
.end()
.find('.logo')
.css('top','-4px')
.append('<span class="white01"></span>')
.append('<span class="white02"></span>')
.find('span')
.css('position','absolute')
.css('left','0px')
.css('display','block')
.css('width','55px')
.css('height','4px')
.css('background-color','white')
.end()
.end()
.end();
});
} else if(16 < $logolistnum){
$thismainArea.find('li').each(function(){
$(this)
.css('overflow','hidden')
.find('a')
.addClass('nummore')
.css('padding-top','14px')
.css('padding-bottom','14px')
.end()
.find('.logo')
.css('top','-8px')
.append('<span class="white01"></span>')
.append('<span class="white02"></span>')
.find('span')
.css('position','absolute')
.css('left','0px')
.css('display','block')
.css('width','55px')
.css('height','4px')
.css('background-color','white')
.end()
.end()
.end();
});
}else{
}
});
appendhtmlheight = $('#sb-player').height();
if($('#sb-wrapper-inner').height < (appendhtmlheight + 93)) {
appendheight = (appendhtmlheight) + 95;
$('#sb-wrapper-inner').height(appendheight);
}

        }
      }
  });
//_isOpen = true;
//_$brandlist.fadeIn(0.2*1000);
}
function closeBox() {
if(!_isOpen) return;
_isOpen = false;
_$brandlist.fadeOut(0.1*1000);
}

//----------------------------------------------------------------------------------------------------
init();
$('#sb-nav').css('cursor','pointer').click(function(){ Shadowbox.close(); });

});

