
$(document).ready(function() 
{
	// general
	navigationInit();
	mailinglistInit();
	preloadImages();
	IE6warning();

	// home
	slideshowInit();

	// news
	videoInit();
	bannerInit();
	
	// gallery
	galleryInit();
});

$(window).load(function()
{
	//facebookInit();
});

//------------------------------------------------------------------------------------------------- NAVIGATION

function navigationInit()
{
	var width = 0;
	var item = $('#nav > li');
	item.each(function() 
	{
		width += $(this).width();
	});
}

//------------------------------------------------------------------------------------------------- SLIDESHOW

function slideshowInit()
{
	$('#welcome .pics').cycle({
		fx: 'fade'
	});
}

//------------------------------------------------------------------------------------------------- MAILINGLIST

function mailinglistInit()
{
	$("#mailing_btn").fancybox({
		'scrolling': 'no',
		'titleShow': false,
		'padding': 0,
		'margin': 0
	});
}

//------------------------------------------------------------------------------------------------- GALLERY

function galleryInit()
{
	$("a.gallerybox").fancybox({
		//titleFormat: formatTitle,
		autoScale: false,
		titlePosition: 'over'
	});
}

function formatTitle(title, currentArray, currentIndex, currentOpts)
{
	if (title!="") return '<div>' + (title && title.length ? title : '' ) + ' (' + (currentIndex + 1) + '/' + currentArray.length + ')</div>';
	else return "";
}

//------------------------------------------------------------------------------------------------- VIDEO

function videoInit()
{
	$("a.videobox").click(function() {
		$.fancybox({
			'padding': 0,
			'autoScale': false,
			'transitionIn': 'none',
			'transitionOut': 'none',
			'title': this.title,
			'width': 680,
			'height': 495,
			'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type': 'swf',
			'swf': { 'wmode': 'transparent', 'allowfullscreen': 'true'}
		});
		
		return false;
	});
}

//------------------------------------------------------------------------------------------------- VIDEO

function bannerInit()
{
	$('#banner').flash({
	    src: '/swf/banner.swf',
	    width: $('#banner').width(),
	    height: 268,
		menu: false,
		wmode: 'transparent'
	});
}

//------------------------------------------------------------------------------------------------- VIDEO

function preloadImages()
{
	jQuery.preLoadImages("/images/template/en/nav/Home_2.gif", "/images/template/en/nav/Home_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/Collection_2.gif", "/images/template/en/nav/Collection_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/Accessoires_2.gif", "/images/template/en/nav/Accessoires_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/BirthCards_2.gif", "/images/template/en/nav/BirthCards_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/Gallery_2.gif", "/images/template/en/nav/Gallery_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/Info_2.gif", "/images/template/en/nav/Info_3.gif");
	jQuery.preLoadImages("/images/template/en/nav/Shops_2.gif", "/images/template/en/nav/Shops_3.gif");
}

//------------------------------------------------------------------------------------------------- FACEBOOK

function facebookInit()
{
	$('#fbstream').load('http://www.facebook.com/home.php?ref=logo#!/pages/Lovely-Mariquita/20943188908296&amp;width=265&amp;colorscheme=light&amp;connections=10&amp;stream=false&amp;header=false&amp;height=300'); 
}

//------------------------------------------------------------------------------------------------- IE6 WARNING

function IE6warning()
{
    if (jQuery.browser.msie && jQuery.browser.version.substr(0, 1) == '6') 
	{
        var warningText = 'Please update your browser for a safer and richer experience.'
        
        $('body').prepend($('<a/>', {
            id: 'IE6warning',
            text: warningText,
            href: 'http://www.browserchoice.eu/',
            target: '_blank'
        }));
        
        $('#IE6warning').css({
            'display': 'block',
            'position': 'relative',
            'z-index': '2'
        }).hide().slideDown();
    }
}

//------------------------------------------------------------------------------------------------- IMAGE HOVER

$(function() {
    $('img[data-hover]').hover(function() {
        $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp');
    }).each(function() {
        $('<img />').attr('src', $(this).attr('data-hover'));
    });;
});

