
///////////////////////  DOCUMENT READY  //////////////////////////////

jQuery(document).ready(function() { //on DOM ready
	ajaxing();
	abrir();
	initializeImageResize();
	ResizeContent();
	makeColumns();
	horizScroll();
	myHistory();	
});
////////////////////////  SLIDE ////////////////
function sliding() {
	jQuery(window).mousemove(function(event) {
	});
}
////////////////////////  MAX IMAGE INICIO ////////////////

////////////////////////  HORIZONTAL SCROLL  ////////////////

function horizScroll() {
	jQuery('.scroll-pane').jScrollPane({showArrows: true});
	jQuery("a.jspArrowLeft").html("<");
	jQuery("a.jspArrowRight").html(">");
}
///////////////////////  RESIZE  /////////////////	


var isiPad = (navigator.userAgent.match(/iPad/i) != null) || (navigator.userAgent.match(/iPhone/i) != null);

function initializeImageResize() {
	jQuery('#inicio img, #big_img img').each(function() {
			jQuery(this).data('myOrigImgR', jQuery(this).attr('width') / jQuery(this).attr('height'));
	});
	jQuery('#hscroll img').each(function() {
			jQuery(this).data('myOrigImgR2', jQuery(this).attr('width') / jQuery(this).attr('height'));
	});
	jQuery('#hscroll2 img').each(function() {
			jQuery(this).data('myOrigImgR4', jQuery(this).attr('width') / jQuery(this).attr('height'));
	});
	jQuery('#content-page img').each(function() {
			jQuery(this).data('myOrigImgR3', jQuery(this).attr('width') / jQuery(this).attr('height'));
	});
	
	

}
function fullScreen() {
	
}
function ResizeContent() {
	var myAvailH = jQuery(window).height();
	var myAvailW = jQuery(window).width();
	var myAvailW2 = jQuery(window).width() - '81';
	var myAvailH2 = jQuery(window).height() - '121';
	var myAvailW3 = jQuery(window).width();
	var myAvailH3 = jQuery(window).height();
	
	jQuery('#hscroll .jspContainer').css('height', (myAvailH2 + 8)+'px');
	jQuery('#inicio').css('height', (myAvailH + 15)+'px');
	jQuery('#inicio').css('width', (myAvailW + 15)+'px');
	jQuery('#big_img').css('width', myAvailW3);
	jQuery('#big_img').css('height', myAvailH3);
	
	jQuery('#hscroll').css('height', (myAvailH2 + 16)+'px');
	jQuery('#hscroll').css('width', myAvailW2);
	jQuery('#hscroll2').css('height', (myAvailH2 + 16)+'px');
	jQuery('#hscroll2').css('width', myAvailW2);
	jQuery('#content-page').css('height', (myAvailH2)+'px');
	/*
if (!isiPad) {
		jQuery('#inicio').css('height', myAvailH);
		jQuery('#hscroll').css('height', myAvailH2 + '16');
		jQuery('.jspContainer').css('height', myAvailH2 + '16');
	} else {
		jQuery('#hscroll .jspContainer').css('height', (myAvailH2 + 16)+'px');
		jQuery('#inicio').css('height', myAvailH);
		jQuery('#inicio').css('width', myAvailW);
		jQuery('#hscroll').css('height', (myAvailH2 + 16)+'px');
		jQuery('.jspContainer').css('height',(myAvailH2 + 16)+'px');
		jQuery('#hscroll').css('width', (myAvailW2)+'px');
		jQuery('#content-page').css('height', (myAvailH2 + 16)+'px');
		
	}
*/
	var myAvailR = myAvailW / myAvailH;
	var myAvailR2 = myAvailW2 / myAvailH2;
			
	jQuery('#inicio img').each(function() {
		var myNewH =  Math.round((myAvailW) / jQuery(this).data('myOrigImgR'));
		jQuery(this).attr('width', (myAvailW + 15));
		jQuery(this).attr('height', myNewH);
		jQuery(this).attr('title', '');
	});	
	jQuery('#big_img img').each(function() {
		var myNewH3 =  Math.round((myAvailW3) / jQuery(this).data('myOrigImgR'));
		jQuery(this).attr('width', myAvailW3);
		jQuery(this).attr('height', myNewH3);
		jQuery(this).attr('title', '');
	});	
	jQuery('#hscroll img').each(function() {
		var myNewW2 =  Math.round((myAvailH2) * jQuery(this).data('myOrigImgR2'));
		
		jQuery(this).attr('width', myNewW2);
		jQuery(this).attr('height', myAvailH2);
		jQuery(this).attr('title', '');
	});			
	jQuery('#hscroll2 img').each(function() {
		var imgNewH = (myAvailH2 - '14') / '3';
		var myNewW4 =  Math.round((imgNewH) * jQuery(this).data('myOrigImgR4'));
		
		jQuery(this).attr('width', myNewW4);
		jQuery(this).attr('height', imgNewH);
		jQuery(this).attr('title', '');
	});		
	jQuery('#content-page img').each(function() {
		var myNewW3 =  Math.round(myAvailH2 * jQuery(this).data('myOrigImgR3'));
				
		jQuery(this).attr('width', myNewW3);
		jQuery(this).attr('height', myAvailH2);
		jQuery(this).attr('title', '');
	});
			
	if (jQuery('#inicio').width() < myAvailW) {
		jQuery('#inicio').css('width', myAvailW);
	} else {
		jQuery('#inicio').css('width', myAvailW);
	}		
	if (jQuery('#hscroll').width() < myAvailW2) {
		jQuery('#hscroll').css('width', myAvailW2);
	} else {
		jQuery('#hscroll').css('width', myAvailW2);
	}
	if (jQuery('#content-page').width() < myAvailW2) {
		jQuery('#content-page').css('width', myAvailW2);
	} else {
		jQuery('#content-page').css('width', myAvailW2);
	}/*

	var myAvailH = jQuery(window).height() - jQuery('#footer').height() - '80';
			var myAvailW = jQuery(window).width() - '81';
			if (!isiPad) {
			jQuery('#scroll').css('height', myAvailH);
			} else {
			jQuery('#scroll').css('height', myAvailH);
			jQuery('#allpics').css('width', myAvailW);
			}
			var myAvailR = myAvailW / myAvailH;
			
			jQuery('#scroll img').each(function() {
					var myNewW =  Math.round(myAvailH * jQuery(this).data('myOrigImgR'));
				
					jQuery(this).attr('width', myNewW);
					jQuery(this).attr('height', myAvailH);
					jQuery(this).attr('title', '');
			});
			
			if (jQuery('#allpics').width() < myAvailW) {
				jQuery('#scroll').css('width', myAvailW);
			} else {
				jQuery('#scroll').css('width', jQuery('#allpics').width());
			}
*/

}
/////////////////////////  RESIZE WINDOW  ////////////////////////


jQuery(window).resize(function() {
			jQuery('.scroll-pane').each(function() {
				jQuery(this).jScrollPane({showArrows:true});
				jQuery("a.jspArrowLeft").html("<");
				jQuery("a.jspArrowRight").html(">");
				ResizeContent();
				var api = jQuery(this).data('jsp');
				var throttleTimeout;
				jQuery(window).bind('resize',function(){
					jQuery(this).jScrollPane({showArrows:true});
					jQuery("a.jspArrowLeft").html("<");
					jQuery("a.jspArrowRight").html(">");
					ResizeContent();
					if (jQuery.browser.msie) {
						// IE fires multiple resize events while you are dragging the browser window which
						// causes it to crash if you try to update the scrollpane on every one. So we need
						// to throttle it to fire a maximum of once every 50 milliseconds...
						if (!throttleTimeout) {
							throttleTimeout = setTimeout(function(){
									api.reinitialise();
									throttleTimeout = null;
							},50);
						}
					} else {
						api.reinitialise();
					}
				});
			});
});


///////////////////////  DROP DOWNS  //////////////////////////////


function abrir(){
	setTimeout(function(){
		jQuery('#cat-desc .show').slideToggle();
		jQuery('#cat-desc span.masmenos').toggle();
	}, 20000);
	jQuery('#sidebar h2.widget-title').append('<span class="masmenos"><img src="http://www.lajoyadesign.com/wp-content/themes/lajoya/img/abajo.jpg" /></span><span class="masmenos" style="display:none"><img src="http://www.lajoyadesign.com/wp-content/themes/lajoya/img/arriba.jpg" /></span>');
	jQuery('#cat-desc h2.widget-title a').attr('href','#').click(function() {
		jQuery('#cat-desc .show').slideToggle();
		jQuery('#cat-desc span.masmenos').toggle();
		return false;
	});	
	jQuery('#primary-sidebar h2.widget-title').bind('click',function() {
		jQuery('.menu-general-container, .menu-general_en-container').slideDown();
		return false;
	}).parent().parent().bind('mouseleave',function(){
		jQuery('.menu-general-container, .menu-general_en-container').slideUp();
		return false;
    });
	jQuery('#secondary-sidebar h2.widget-title').bind('click',function() {
		jQuery('.menu-colecciones-container, .menu-collections-container').slideDown();
		jQuery('.menu-lookbooks-container').slideDown();
		return false;
	}).parent().parent().bind('mouseleave',function(){
		jQuery('.menu-colecciones-container, .menu-collections-container').slideUp();
		jQuery('.menu-lookbooks-container').slideUp();
		return false;
    });
}



///////////////////////  AJAXING  //////////////////////////////


function ajaxing(){
	cfct = {}

	cfct.loading = function() {
		return '<div class="loading">  LOADING  </div>';
	}
	cfct.ajax_post_content = function() {
		jQuery('div.col-item a.transp, div.col-item a.press-hover').unbind().click(function() {
			var link =  jQuery(this).attr('href');
			var post_id = jQuery(this).attr('rev').replace('post-', '');
			var excerpt = jQuery('#post-excerpt-' + post_id);
			var target = jQuery('#post-content-' + post_id + '-target');
			target.addClass('over');
			target.html(cfct.loading()).show().load(link).hide().fadeIn().find('#close').click(function() {
				jQuery(this).parent().fadeOut().html('');
			})
			sliding();
			fullScreen();
			target.find('#close').click(function() {
				jQuery(this).parent().fadeOut().html('');
			})
			return false;
		});
	}


	jQuery(function($) {
		// :first-child fix for IE on nav
		$('.nav li:first-child').addClass('first-child');
		// :first-child fix for IE
		$('.comment .comment-content p:last-child').addClass('last-child');
		// :hover fix for full articles in IE
		$('.full').mouseover(function() {
			$(this).addClass('hover');
		});
		$('.full').mouseout(function() {
			$(this).removeClass('hover');
		});

		// Suckerfish dropdowns IE :hover fix
		$('.nav li').mouseover(function() {
			$(this).addClass('hover');
		});
		$('.nav li').mouseout(function() {
			$(this).removeClass('hover');
		});
	
		if ((!$.browser.msie || $.browser.version.substr(0,1) != '6') && typeof CFCT_AJAX_LOAD != 'undefined' && CFCT_AJAX_LOAD) {
			cfct.ajax_post_content();
		}
		$('.nav li a').removeAttr('title');
	
	});
	

}
///////////////////////  PRESS COLUMNS  //////////////////////////////

function makeColumns(){
        jQuery('#hscroll2 #allpics').nwrapper({
			wrapEvery      : 3,
			//defaultClasses : true,
			//extraClasses   : ['class1', 'class2'],
			htmlStructure  : 'td'
		});  
		jQuery('td').wrapAll('<tr />');
		jQuery('tr').wrap('<table cellpadding="0" cellspacing="0" border="0" />');
}

///////////////////////  HISTORY URL  //////////////////////////////

function myHistory() {
	/*
function load(num) {
    	jQuery('#content').load(num +".html");
    }

    jQuery.history.init(function(url) {
    	load(url == "" ? "1" : url);
    });
*/

    jQuery('div.col-item a.transp').live('click', function(e) {
    	var url = jQuery(this).attr('rev');
    	url = url.replace(/^.*#/, '');
    	jQuery.history.load(url);
    	return false;
    });
}



