var required_page = 'home';
var cycle_timeout = 5000;
var cycle_speed = 1250;
var gallery_main_image = 'default';

jQuery.fn.extend({
  
  photoFade: function(options){
    options = options || {};
    if(options.page) required_page = options.page;
    if(options.timeout) cycle_timeout = options.timeout;
    if(options.speed) cycle_speed = options.speed;
    if(options.gallery_image) gallery_main_image = options.gallery_image;
    
		$(document).ready(function(){
			switch(required_page){
				case 'home': {
					
					var container = $('#main-home');
				
					$(window).load(function(){
						$(container).css({'background' : '#FFF'});
						$(container).animate({'height':$(container).children(':first-child').height()}, function(){
							$(container).children(':first-child').fadeIn(cycle_speed, function(){
								$(container).cycle({
									timeout: cycle_timeout,
									speed: cycle_speed
								});
							});
						});
					});
				}
				break;
				
				case 'biography': {
					var biographySplash = document.createElement('img');
					biographySplash.src = 'images/frontend/biography-bg.jpg';
					$(biographySplash).css({'display' : 'none'});
					var container = $('#biography-bg');
					$(container).css({'background' : 'url(\'images/loading.gif\') center no-repeat'});
					$(container).append(biographySplash);
					$(window).load(function(){
						$(container).css({'background' : '#FFF'});
						$(biographySplash).fadeIn(1250);
					});
				}
				break;
				
				case 'clients': {
					var clientsSplash = document.createElement('img');
					clientsSplash.src = 'images/frontend/clients-bg.jpg';
					$(clientsSplash).css({'display' : 'none'});
					var container = $('#clients-bg');
					$(container).css({'background' : 'url(\'images/loading.gif\') center no-repeat'});
					$(container).append(clientsSplash);
					$(window).load(function(){
						$(container).css({'background' : '#FFF'});
						$(clientsSplash).fadeIn(1250);
					});
				}
				break;
				
				case 'contacts': {
					var contactsSplash = document.createElement('img');
					contactsSplash.src = 'images/frontend/contacts-bg.jpg';
					$(contactsSplash).css({'display' : 'none'});
					
					var container = $('#contact-bg');
					$(container).css({'background' : 'url(\'images/loading.gif\') center no-repeat'});
					$(container).append(contactsSplash);
					$(window).load(function(){
						$(container).css({'background' : '#FFF'});
						$(contactsSplash).fadeIn(1250);
					});
				}
				break;
				
				case 'gallery-home': {
					$('ul.gallery-menu').hide();
					var gallerySplash = document.createElement('img');
					gallerySplash.src = gallery_main_image;
					gallerySplash.id = 'gallery-splash';
					$(gallerySplash).css({'display' : 'none'});
					
					var container = $('#main-content');
					$(container).css({'background' : 'url(\'images/loading.gif\') center no-repeat'});
					$('#gallery-main').append(gallerySplash);
					$(window).load(function(){
						$(container).css({'background' : '#FFF'});
						$(gallerySplash).fadeIn(1250,function(){
							$('ul.gallery-menu').fadeIn(400);
						});
					});
				}
				break;
				
				case 'blog': {
					$('div.post-attachments').find('img').each(function(){
						var currEl = $(this);
						var description = '';
						$(currEl).click(function(){
							if(window.blog_attachment)
								blog_attachment.unload();
							loading = new Boxy('<img src="images/loading.gif" style="display:block; margin:0 auto" alt="Loading" title="Loading" /><h5>Please wait for loading...</h5>', {title: 'Loading'});
							if($(currEl).attr('alt')!=''){
								description = '<p class="blog-attachment-description">'+$(currEl).attr('alt')+'</p>'
							}
							blog_attachment = new Boxy('<img src="'+$(currEl).attr('rel')+'" />'+description, {title: 'Blog attachment', show: false, behaviours: function(r){
								$(r).load(function(){
									loading.unload();
								  blog_attachment.center();
								  blog_attachment.show();
								  $('.boxy-inner').css({'background':'#343434'});
								  $('.boxy-content').css({'padding':'0'});
								});
							}});
						});
					});		
				}
				break;
			}			
		});
	}
});

/*
$.fn.cycle.defaults = { 
    timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance) 
    speed:         1000,  // speed of the transition (any valid fx speed value) 
    next:          null,  // id of element to use as click trigger for next slide 
    prev:          null,  // id of element to use as click trigger for previous slide 
    before:        null,  // transition callback (scope set to element to be shown) 
    after:         null,  // transition callback (scope set to element that was shown) 
    height:       'auto', // container height 
    sync:          1,     // true if in/out transitions should occur simultaneously 
    fit:           0,     // force slides to fit container 
    pause:         0,     // true to enable "pause on hover" 
    delay:         0,     // additional delay (in ms) for first transition (hint: can be negative) 
    slideExpr:     null   // expression for selecting slides (if something other than all children is required) 
};
*/
