$(document).ready(function(){
initTooltip();
clearInputs();
//initMenu();
initBtnHover();
initSeachPopup();
ieHover('.options li, .column .title h3, .tools li');
$("#hd li.fairmont a").attr("target","_blank");
$('select').not('.non_custom select').customSelect();
$('input').customCheckbox();
initPhotoPopup();
});
function initGallery( divId, ulClassName ){
/*--- gallery like 1 ---*/
$('#' + divId).each(function(){
var gall_hold = $(this);
var list_h = gall_hold.find('.' + ulClassName );
var _step = list_h.parent().outerWidth();
var list_w = list_h.children().length*list_h.children().outerWidth();
var _m = list_h.children().index(list_h.children('.active'))*_step;
list_h.children().removeClass('active');
if(_m < 0) _m = 0;
list_h.css('margin-left', -_m);
gall_hold.find('.btn_prev').click(function(){
changeEl(false);
return false;
});
gall_hold.find('.btn_next').click(function(){
changeEl(true);
return false;
});
function changeEl(_flag){
if(_flag){
if(_m + _step <= list_w - _step) _m += _step;
else _m = 0;
}
else{
if(_m - _step >= 0) _m -= _step;
else _m = list_w - _step;
}
list_h.animate({marginLeft: -_m}, {queue:false, duration:400});
}
});
}
/*--- Upload function ---*/
function initUpload(){
$('.share_area .upload_photos').each(function(){
var _el = $(this).find('ul li:last');
$(this).find('.more a').click(function(){
_el.parent().height(_el.parent().height());
for(var i = 0; i < 5; i++) _el.after(_el.clone(true));
_el.parent().animate({height: '+='+_el.outerHeight()*5}, 300, function(){
$(this).height('auto');
clearInputs();
});
return false;
});
});
$('.share_area .tags').each(function(){
var _box = $(this).find('.own_tags textarea');
var box_text = _box.attr('value');
$(this).find('.tags_list .btn_plus').click(function(){
var _text = $(this).parent().children('strong').html();
if(_box.attr('value') == box_text) _box.attr('value','');
if(_box.attr('value') == '') _box.attr('value', _text);
else _box.attr('value', _box.attr('value') + ', ' + _text);
return false;
});
});
}
/*--- photo popup function ---*/
function initPhotoPopup(){
var _popup = $('#photo_popup');
if(_popup.length){
$(document.body).click(function(){
if(_f) _popup.fadeOut(200);
_f = false;
});
_popup.find('.btn_close').click(function(){
_popup.fadeOut(200);
_f = false;
return false;
});
_popup.mouseenter(function(){
_f = false;
}).mouseleave(function(){
_f = true;
});
var _f = false;
$('.photos .all_photos li > a').live('click', function () {
_f = false;
var _btn = $(this);
var desc = _btn.parent().find('.description').clone(true);
desc.css({'height':'auto', 'margin-top':'0','overflow':'visible'});
_popup.find('.popup_text').html('').append( desc );
_popup.css('top', $(window).scrollTop() - 200).fadeIn(200);
return false;
});
}
}
/*--- photo gallery function ---*/
function initPhotoGall(){
$('.photo_gallery').each(function(){
var _btn = $(this).find('.preview ul a');
var _a = _btn.index(_btn.filter('.active:eq(0)'));
if(_a == -1) _a = 0;
_btn.removeClass('active').eq(_a).addClass('active');
var _btn_type = _btn.eq(_a).attr('type');
if ( _btn_type == "photo" ) {
if($(this).find('.big_photo img').length == 0) $(this).find('.big_photo').append('
');
var b_img = $(this).find('.big_photo img');
var thick_img = $(this).find('.big_photo .thickbox');
thick_img.attr('href', _btn.eq(_a).attr('href').replace(/[?].*/,'')).attr('alt', _btn.eq(_a).attr('rel'));
var img_info = $(this).find('.options p');
b_img.attr('src', _btn.eq(_a).attr('href')).attr('alt', _btn.eq(_a).attr('rel'));
img_info.html(_btn.eq(_a).attr('rel'));
} else if ( _btn_type == 'video'){
$(this).find('.big_photo').css("display","none");
$(this).find('.video').css("display","block");
$(this).find('.youtube').css("display","none");
var img_info = $(this).find('.options p');
img_info.html(_btn.eq(_a).attr('rel'));
} else if ( _btn_type == 'youtube' ){
$(this).find('.big_photo').css("display","none");
$(this).find('.video').css("display","none");
$(this).find('.youtube').css("display","block");
var img_info = $(this).find('.options p');
img_info.html('Youtube video');
}
var _f1 = true;
_btn.click(function(){
if(_f1 && (_btn.index(this) != _a)){
_f1 = false;
var type = $(this).attr('type');
if ( type == "photo") {
$('.photo_gallery').find('.big_photo').css("display","block");
$('.photo_gallery').find('.video').css("display","none");
$('.photo_gallery').find('.youtube').css("display","none");
var t_img = $('
').hide();
var thick_img = $('.photo_gallery .big_photo .thickbox');
thick_img.attr('href', $(this).attr('href').replace(/[?].*/,'')).attr('alt', _btn.eq(_a).attr('rel'));
b_img.parent().append(t_img);
b_img.fadeOut(300,function(){
$(this).remove();
t_img.css({opacity: 0, display:'block'}).animate({opacity: 1}, 200, function(){
b_img = t_img;
_f1 = true;
});
});
img_info.fadeOut(200, function(){
$(this).html(t_img.attr('alt')).fadeIn(200);
});
} else if ( type == "video" ) {
$('.photo_gallery').find('.video').css("display","block");
$('.photo_gallery').find('.youtube').css("display","none");
$('.photo_gallery').find('.big_photo').css("display","none");
var caption = $(this).attr('rel');
img_info.fadeOut(200, function(){
$(this).html( caption ).fadeIn(200);
_f1 = true;
});
} else if ( type == "youtube" ) {
$('.photo_gallery').find('.youtube').css("display","block");
$('.photo_gallery').find('.video').css("display","none");
$('.photo_gallery').find('.big_photo').css("display","none");
var caption = $(this).attr('rel');
img_info.fadeOut(200, function(){
$(this).html( caption ).fadeIn(200);
_f1 = true;
});
}
_btn.eq(_a).removeClass('active');
$(this).addClass('active');
_a = _btn.index(this);
}
return false;
});
var btn_h = $(this).find('.preview .mask ul');
var btn_h_parent_h = btn_h.parent().outerHeight();
var _f2 = true;
$(this).find('.preview > p > a').click(function(){
if(this.innerHTML.indexOf('View') != -1){
btn_h.parent().animate({ height: btn_h.outerHeight()}, {queue:false, duration:300});
this.innerHTML = 'Collapse';
}
else{
btn_h.parent().animate({ height: 150}, {queue:false, duration:300});
this.innerHTML = 'View All';
}
return false;
});
});
}
/*---- IE6 hover function ---*/
function ieHover(h_list) {
if ($.browser.msie && $.browser.version < 7) {
$(h_list).hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
}
}
/*--- tabs function ---*/
function initTabs(h_list) {
$('.tab_area').each(function() {
var _btn = $(this).find('.tabset a');
var box_h = $(this).children('.tab_holder');
var _a = _btn.index(_btn.filter('.active').eq(0));
if(_a == -1) _a = 0;
_btn.each(function(_ind, _el) {
this._box = box_h.children('.'+_el.href.substr(_el.href.indexOf("#") + 1));
if(_ind == _a) this._box.show();
else this._box.hide();
if(box_h.parent().hasClass('must_hover')){
_el.onmouseover = function(){
if(_ind != _a){
_btn.get(_a)._box.hide();
_btn.eq(_a).removeClass('active');
this._box.show();
$(this).addClass('active');
_a = _ind;
$('select').customSelect();
}
}
}
else{
_el.onclick = function() {
if(_ind != _a){
_btn.get(_a)._box.hide();
_btn.eq(_a).removeClass('active');
this._box.show();
$(this).addClass('active');
_a = _ind;
$('select').customSelect();
}
return false;
}
}
});
});
}
function initTabsHover(h_list) {
$('.tab_hover').each(function() {
var _btn = $(this).find('.tabset a');
var box_h = $(this).children('.tab_holder');
var _a = _btn.index(_btn.filter('.active').eq(0));
if(_a == -1) _a = 0;
_btn.each(function(_ind, _el) {
this._box = box_h.children('.'+_el.href.substr(_el.href.indexOf("#") + 1));
if(_ind == _a) this._box.show();
else this._box.hide();
if(box_h.parent().hasClass('must_hover')){
_el.onmouseover = function(){
if(_ind != _a){
_btn.get(_a)._box.hide();
_btn.eq(_a).removeClass('active');
this._box.show();
$(this).addClass('active');
_a = _ind;
$('select').customSelect();
}
}
}
else{
_el.onmouseover = function() {
if(_ind != _a){
_btn.get(_a)._box.hide();
_btn.eq(_a).removeClass('active');
this._box.show();
$(this).addClass('active');
_a = _ind;
$('select').customSelect();
}
return false;
}
}
});
});
}
/*---- clear inputs function ---*/
function clearInputs(){
$('input:text, input:password, textarea').each(function(){
if(!this.val) this.val = this.value;
this.onfocus = function(){
if(this.value == 'Enter a title . . .' ||
this.value == 'Enter a description . . .' ||
this.value == 'write a caption for your video here' ||
this.value.replace(/[^a-zA-Z 0-9]+/g,'') == 'Insert YouTube link here' ||
this.value == 'tags are a one-word description that help us organize your stories. enter your tags here' ||
this.value == 'write a caption for your photo here' ||
this.value == 'looking for something?' ) this.value = '';
}
this.onblur = function(){
if(this.value == '') this.value = this.val;
}
});
}
/*--- menu accordion function ---*/
function initMenu(){
$('.side_nav > ul').each(function(){
var _list = $(this).children('li:has(".slide")');
var _a = _list.index(_list.filter('.active:eq(0)'));
_list.each(function(_i){
this._btn = $(this).children('a').eq(0);
this._box = $(this).children('.slide').eq(0);
if(_i == _a) this._box.show();
else this._box.hide();
this._btn.click(function(){
if(_a != -1){
_list.get(_a)._box.stop().animate({height: 0}, 300, function(){
$(this).css({display: 'none', height: 'auto'});
$(this).parent().removeClass('active');
});
}
if(_a != _i){
_list.eq(_i).addClass('active');
if(!_list.get(_i)._box.is(':animated')){
_list.get(_i)._h = _list.get(_i)._box.height();
_list.get(_i)._box.css({height: 0, display:'block'});
}
_list.get(_i)._box.stop().animate({ height: _list.get(_i)._h}, 300, function(){
$(this).height('auto');
});
_a = _i;
}
else{
_a = -1;
}
return false;
});
});
$(this).children().not(_list).children('a').click(function(){
if(_a != -1){
_list.get(_a)._box.stop().animate({height: 0}, 300, function(){
$(this).css({display: 'none', height: 'auto'});
$(this).parent().removeClass('active');
});
_a = -1;
}
});
});
}
/*--- button hover function ---*/
function initBtnHover(){
$('.over_btn').hover(
function(){
this.src = this.src.replace( /\.gif$/, '-h.gif' );
this.src = this.src.replace( /\.jpg$/, '-h.jpg' );
},
function(){
this.src = this.src.replace( /-h\.gif$/, '.gif' );
this.src = this.src.replace( /-h\.jpg$/, '.jpg' );
}
);
}
/*--- search popup function ---*/
function initSeachPopup(){
var _popup = $('.search_panel .popup');
var btn_o = $('.search_panel .advanced_search');
var btn_c = _popup.find('a.close');
if(_popup.length){
var _f = true;
btn_o.click(function(){
if(_f){
_f = false;
var _h = _popup.height();
$(this).animate({opacity: 0}, 200, function(){
_popup.css({height: 0, visibility: 'visible'}).animate({height: _h}, 400, function(){
_f = true;
});
});
}
return false;
});
btn_c.click(function(){
if(_f){
_f = false;
_popup.animate({height: 0}, 200, function(){
_popup.css({height: 'auto', visibility: 'hidden'});
btn_o.animate({opacity: 1}, 400, function(){
_f = true;
});
});
}
return false;
});
}
}
/*--- tooltip function ---*/
function initTooltip(){
var _tooltip = $('