/* Author: 

*/

 function initialize() {
    var latlng = new google.maps.LatLng(51.538247,-0.209229);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("full-screen-image"),
        myOptions);

	var image = new google.maps.MarkerImage('img/map-icon.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(52, 65),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(7, 65));
      
	var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: image
    });

  }

  jQuery(function($){
	
	$(window).bind('resize', browserChange);
		browserChange();
		function browserChange(){
			
			
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$('#what-we-have').width($(window).width());
				$('.bio-right-arrow').css({'right':'auto', 'left':$(window).width()-$('.bio-right-arrow').width()-10});
			}
		}
		
	$(window).bind('resize', teamChange);
		teamChange();
		function teamChange(){
			
			
			if ($.browser.msie && $.browser.version.substr(0,1)<7) {
				$('#our-biographies').width($(window).width());
				$('.bio-right-arrow').css({'right':'auto', 'left':$(window).width()-$('.bio-right-arrow').width()-10});
			}
		}	
	
	var asideW = $('aside li').width() * ($('aside li').length - 1) + 30;
  
 	$('aside').width(asideW);
	
	$('img').live('mousedown',function(event) {
		switch (event.which) {
			
			case 3:
				event.stopPropagation();
				$(document).bind("contextmenu",function(e){
             		 return false;
   				 }); 
				alert('This image is protected by copyright.  For further assistance please contact Banana Split.');
				break;
		}
	});

	
	
	function checkdocsize()
	{
		var documentH = $(document).height();
		var windowH = $(window).height();  
		if(windowH < 800)
		{
			$('aside').css('margin-bottom', '50px');
			var heightt = documentH - 95 - $('footer').height();
			$('#full-screen-image').css('position', 'fixed !important');
			
		}
		else
		{
			$('#full-screen-image').css('position', 'absolute !important');
		}
	}
	
	$(window).resize(function() {
  		checkdocsize();
	});

	checkdocsize();
	
	if ($('#landing').size()>0) {
      if ($.browser.msie && $.browser.version.substr(0,1)<7) {
          window.location = "home.php"
      }

     // $('#landing-logo').hide();
      $('header nav ul').css('margin-left','-' + $('header nav ul').width() + 'px');
      $('footer .site-by').css('margin-left','-110px');
      $('footer ul').css('margin-right','-400px');
      $('#logo').css('margin-left','-301px');
      $('body').append('<div id="top-shutter">&nbsp;</div><div id="bottom-shutter">&nbsp;</div>');

      function nextPage() {
        $('#landing-logo').stop().animate({
          'left':'-858',
          'opacity':'0'
        },1500, 'easeOutQuart');
        $('#logo').stop().animate({
          'margin-left':'15'
        },1000, 'easeOutQuart');
        $('header nav ul').stop().animate({
          'margin-left':'15'
        },1000, function(){
          window.location = "home.php"
        });
      }
  
      $('#top-shutter, #bottom-shutter').animate({
        'height':'0px'
      },1500,function(){
        $('header nav ul').animate({
          'margin-left':'46px'
        }, 1500, 'easeOutQuart');
        $('footer .site-by').animate({
          'margin-left':'0px'
        }, 1500, 'easeOutQuart');
        $('footer ul').animate({
          'margin-right':'0px'
        }, 1500, 'easeOutQuart');
        $(this).remove();
        setTimeout(nextPage,2000);
      })

      $('#landing-logo').fadeIn(2000);
    };

    function imageTransition(){
		imgWidth=$('#full-screen-image').children('img:visible').width();
        imgHeight=$('#full-screen-image').children('img:visible').height();
	if($('#full-screen-image img').size()==1){
	  if ($('#overlay').size()>0) {  
        $('#overlay').before('<img src="'+linkImage+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" />')
        $('#overlay').before('<img src="'+linkImage.replace('bw','single')+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" />')
        $('#overlay').before('<img src="'+linkImage.replace('single','colour')+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" />')
      
      } else {
        $('#full-screen-image').append('<img src="'+linkImage+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" class="loadme" />')
        $('#full-screen-image').append('<img src="'+linkImage.replace('bw','single')+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" />')
        $('#full-screen-image').append('<img src="'+linkImage.replace('bw','colour')+'" alt="Full Size Image" width="'+imgWidth+'" height="'+imgHeight+'" style="display:none;" />')
      };
		
	
      $("#full-screen-image").fullSizeImage('refresh');
	  
	  

        $('.loadme').preload({
          onRequest:function(){
            $('body').append('<div class="loading">&nbsp;</div>');
            $('.loadme').removeClass('loadme');
          },
          onFinish: function(){
			 
            
            $("#full-screen-image").fullSizeImage('refresh');
			$('#full-screen-image img:eq(0)').fadeOut(3000, function() {$('.loading').remove();});
			
            $('#full-screen-image img:eq(1)').fadeIn(3000);
            $('#full-screen-image img:eq(2)').delay(2000).fadeIn(3000);
            $('#full-screen-image img:eq(3)').delay(4000).fadeIn(3000,function(){
																			   	
				
            	$('#full-screen-image img:eq(0)').remove();
            	$('#full-screen-image img:eq(0)').remove();
            	$('#full-screen-image img:eq(0)').remove();
			});
               
          }
        });
											}
    }
//
//    $('ul.page-links li').mouseenter(function(){
//      $('.overlay', this).fadeIn(500);
//    }).mouseleave(function(){/=
//      $('.overlay', this).fadeOut(250);
//    })

 /*    $('ul.page-links li a').click(function(e){
      e.preventDefault();
      linkRel = $(this).attr('rel');
     
      if ($('.what-we-do-link:visible').size()>0) {
        $('#what-we-content').animate({'width':'0'},function(){
          $('.what-we-do-link:visible').hide();
          $('#'+linkRel).css('display','block');
          $('#what-we-content').animate({'width':'330'});
        });
      } else {
        $('#'+linkRel).css('display','block');
        $('#what-we-content').animate({'width':'330'});
      };
      $('#full-screen-image').load( $(this).attr('href') + ' #full-screen-image img', function(){
        $("#full-screen-image").fullSizeImage({ 
             overlayLine: false
        });
        if($('#full-screen-image img').size()>1) {
          $('#full-screen-image img:not(":first")').hide();
          $('#full-screen-image img:first').preload({
            onRequest:function(){
              $('body').append('<div class="loading">&nbsp;</div>');
            },
            onFinish: function(){
              $('.loading').remove();
              setTimeout(function(){
				  $('#full-screen-image img:eq(0)').fadeOut(3000);
				  $('#full-screen-image img:eq(1)').fadeIn(3000);
				  $('#full-screen-image img:eq(2)').delay(2000).fadeIn(3000,function(){
					$('#full-screen-image img:eq(0)').remove();
					$('#full-screen-image img:eq(0)').remove()
				  });
				   
				},2000)
            }
          });
        }
      });

      $('aside').load( $(this).attr('href') + ' aside ul', function(){
        $('aside').stop().animate({
            'left':-($('aside ul').width() - $('aside li:last').width() - parseInt($('aside li:last').css('padding-left').replace('px','')) - parseInt($('aside li:last').css('padding-right').replace('px','')))
          }, 1000, 'easeOutQuad');
           loadAside();
      });
    });
      */
	  
	 if($('#portfolio').size() > 0)
	  {
		  $('#what-image img:first').preload({
          onFinish: function(){
            $("#what-image").fullSizeImage({ 
			 offset: "0,0",
           overlayLine: false
    	  });
           
          }
        });
		  
		  
	  } 

    $('.show-text').click(function(){
      $('section').animate({
        'left':0,
        'padding-right':'15px'
      }, 1000, 'easeOutQuad');
      $(this).fadeOut(500,function(){
        $('.hide-text').fadeIn(500);
      })
    });

    $('.what-we-do-link .hide-text').click(function(){
     $('#what-we-content').animate({'width':'0'},function(){
        $('.what-we-do-link:visible').hide();
      });
    });
	
	$('#enquiry-form .hide-text').click(function(){
     	$('#enquiry-form').slideToggle();
    })
	
	$('.loading').hide();

    $('section:not(".what-we-do-link") .hide-text').click(function(){
      $(this).parent().animate({
        'left':'-300px',
        'padding-right':'30px'
      }, 1000, 'easeOutQuad');
      $(this).fadeOut(500,function(){
        $('.show-text').fadeIn(500);
      })
    });

    loadAside();
var linkImage = 0;
function loadAside() {
    if ($('aside').size()>0) {
      $('.show-thumbs').click(function(){
        if ($('.hide-thumbs').size() < 1) {
          $('aside').stop().animate({
            'left':0
          }, 1000, 'easeOutQuad');

          $('.show-thumbs').addClass('hide-thumbs');
        } else {
          
          $('aside').stop().animate({
            'left':-($('aside ul').width() - $('aside li:last').width() - parseInt($('aside li:last').css('padding-left').replace('px','')) - parseInt($('aside li:last').css('padding-right').replace('px','')))
          }, 1000, 'easeOutQuad');

          $('.hide-thumbs').removeClass('hide-thumbs');
        };

      })


      $('aside a').mouseenter(function(){
        $(this).find('img').fadeOut();
      }).mouseleave(function(){
        $(this).find('img').fadeIn();
      }).click(function(e){
        e.preventDefault();
      })

      $('.show-thumbs').addClass('hide-thumbs');
      setTimeout(function(){
          $('aside').stop().animate({
            'left':-($('aside ul').width() - $('aside li:last').width() - parseInt($('aside li:last').css('padding-left').replace('px','')) - parseInt($('aside li:last').css('padding-right').replace('px','')))
          }, 1000, 'easeOutQuad');

          $('.hide-thumbs').removeClass('hide-thumbs');
      },1000)
      //$('aside').css('left', -($('aside ul').width() - $('aside li:last').width() - parseInt($('aside li:last').css('padding-left').replace('px','')) - parseInt($('aside li:last').css('padding-right').replace('px',''))));
      
      $('aside a').draggable({ 
        revert: true,
        start: function(){
          linkImage = $(this).attr('href');
        }
      })

      $('aside a, #what-we-have article a').click(function(e){
		e.stopPropagation();
        linkImage = $(this).attr('href');
		
        imageTransition(); 
		if($('#locations').length > 0)
	 	{
				 var title = $(this).attr('title');
				 $('footer h2').html('location | ' + title);
		 }
		
		
      });
      
	  var imgTitles = new Array('london', 'venice', 'st petersburg', 'maldives','london','paris','venice','south of france', 'south of france','buckinghamshire','maldives','bahamas');
	  if($('#locations').length > 0)
	  {
		$('#locations aside ul li a img').each(function(i)
		{
			$(this).attr('title', imgTitles[i]);
			$(this).parent('a').attr('title', imgTitles[i]);
			
		});
	  }
		
		
												   
	  
      $('#full-screen-image').droppable({
        accept: "aside a, #what-we-have article a",
        drop:function(e,ui){
          imageTransition();
			 if($('#locations').length > 0)
	 		 {
				 var title = ui.draggable[0].title;
				 $('footer h2').html('location | ' + title);
			 }
		 
        }
      });
    };
}
    if($('#full-screen-image').size()>0) {
      $("#full-screen-image").fullSizeImage({ 
			 offset: "0,0",
           overlayLine: false
      });
	  

      if($('#full-screen-image img').size()>1) {
        $('#full-screen-image img:not(":first")').hide();
        $('#full-screen-image img:first').preload({
          onRequest:function(){
            $('body').append('<div class="loading">&nbsp;</div>');
          },
          onFinish: function(){
            $('.loading').remove();
            setTimeout(function(){
              $('#full-screen-image img:eq(0)').fadeOut(3000);
              $('#full-screen-image img:eq(1)').fadeIn(3000);
              $('#full-screen-image img:eq(2)').delay(2000).fadeIn(3000,function(){
				$('#full-screen-image img:eq(0)').remove();
				$('#full-screen-image img:eq(0)').remove()
			  });
               
            },2000)
          }
        });
      }
    }

    if ($('#our-biographies').size() > 0) {
      var maxLeftPos = $('#our-biographies article:first').width() * $('#our-biographies article').size();
      $('#our-biographies').children('div').width(($('#our-biographies article:first').width() + 765) * $('#our-biographies article').size())


      if ($.browser.msie && $.browser.version.substr(0,1)<7) {
        $('#our-biographies').width($('body').innerWidth());
        $('#our-biographies').height($('#our-biographies header').height() + $('#our-biographies article').height());
        $('footer').width($('body').innerWidth());
        $('.bio-right-arrow').css({
          'left':$('body').innerWidth()-30,
          'right':'auto',
          'width':'20px',
          'top':'30px'
        })
        $('.bio-left-arrow').css({
          'width':'20px',
          'top':'30px'
        })
      }

      $('#our-biographies article img').click(function(){
        if ($(this).parent().children('div').children('div').is(':visible')) {
          $(this).parent().children('div').children('div').fadeOut(function(){
            $(this).parent().animate({'width':'0px'});
            $(this).parent().parent().animate({'width':'166px'});
          });
        } else {
          var moveLeft = $(this).offset().left - 30;
          if ($('#our-biographies article .column-1').is(':visible')) {
            moveLeft = moveLeft - 765;
            if (moveLeft<0) {
              moveLeft = $(this).offset().left - 30;
            };
          }
          if ($('#our-biographies article .column-1').is(':visible')) {
            $('#our-biographies article div div:visible').fadeOut(function(){
              $(this).parent().animate({'width':'0px'});
              $(this).parent().parent().animate({'width':'166px'});
            });
          };
          $(this).parent().animate({'width':'931px'});
          $(this).parent().children('div').animate({'width':'765px'},function(){
            $('div',this).fadeIn();
            $('#our-biographies').children('div').animate({'left':'-='+ moveLeft + 'px'});
          });
        };
      }).mouseenter(function(){
        $(this).addClass('selected');
        $('article img:not(".selected")').stop().animate({'opacity':'0.5'});
      }).mouseleave(function(){
        $('.selected').removeClass('selected');
        $('article img').stop().animate({'opacity':'1'});
      });


      $('.bio-left-arrow').click(function(){
        if (parseInt($('#our-biographies').children('div').css('left').replace('px','')) < 0) {
          $('#our-biographies').children('div:not(":animated")').animate({
            'left':'+=' + '166px'
          })
        };
      });

      $('.bio-right-arrow').click(function(e){
		 $('#our-biographies article').animate({'width':'166px'});
        if(parseInt($('#our-biographies').children('div').css('left').replace('px',''))   >  (-(maxLeftPos - $(window).width() - 62))){
          $('#our-biographies').children('div:not(":animated")').animate({
            'left':'-=' + '166px'
          })
        }
      });
      function checkBioHeight() {
        if ($(window).height() < 510 + $('#our-biographies').height() + $('footer').height()) {
          $('#our-biographies').css({
            'position':'relative',
            'float':'left',
            'display':'inline',
            'clear':'both',
            'bottom':'0'
          })
        } else {
          $('#our-biographies').css({
            'position':'fixed',
            'bottom':'0px'
          })
        };
      }
      checkBioHeight();
      $(window).bind('resize',checkBioHeight)
    };

    if ($('#what-we-have').size() > 0) {
      var maxLeftPos = ($('#what-we-have article:first').width() + 1) * $('#what-we-have article').size();
      $('#what-we-have').children('div').width(($('#what-we-have article:first').width() + 1)  * $('#what-we-have article').size());

      if ($.browser.msie && $.browser.version.substr(0,1)<7) {
        $('#what-we-have').width($('body').innerWidth());
        $('#what-we-have').height($('#what-we-have header').height() + $('#what-we-have article').height());
        $('footer').width($('body').innerWidth());
        $('.bio-right-arrow').css({
          'left':$('body').innerWidth()-30,
          'right':'auto',
          'width':'20px',
          'top':'37px'
        })
        $('.bio-left-arrow').css({
          'width':'20px',
          'top':'37px'
        })
      }


      $('#what-we-have article').click(function(e){
        e.preventDefault();
      }).mouseenter(function(){
        $(this).children().children('img').fadeOut()
      }).mouseleave(function(){
        $(this).children().children('img').fadeIn()
      });

      $('.bio-left-arrow').click(function(){
        if (parseInt($('#what-we-have').children('div').css('left').replace('px','')) < 0) {
          $('#what-we-have').children('div:not(":animated")').animate({
            'left':'+=' + '210px'
          })
        };
      });

      $('.bio-right-arrow').click(function(){
        if(parseInt($('#what-we-have').children('div').css('left').replace('px',''))   >  (-(maxLeftPos - $(window).width() - 62))){
        
          $('#what-we-have').children('div:not(":animated")').animate({
            'left':'-=' + '210px'
          })
        }
      });

      $('.hide-thumbnails').click(function(e){
        e.preventDefault();
        if ($('#what-we-have div').is(":visible")) {
          $('#what-we-have').children('div').slideUp(500, function() {$('.hide-thumbnails').html('show thumbnails'); });
          $('.bio-left-arrow, .bio-right-arrow').slideUp();
        } else {
          $('#what-we-have').children('div').slideDown(500, function() {$('.hide-thumbnails').html('hide thumbnails'); });
          $('.bio-left-arrow, .bio-right-arrow').slideDown();
		
        };
      })

      function whatWeTransition(){
        imgWidth=$('#what-image').children('img:visible').width();
        imgHeight=$('#what-image').children('img:visible').height();
        $('#what-image').append('<img src="'+linkImage+'" width="'+imgWidth+'" height="'+imgHeight+'" alt="Banana Split" class="preload" style="display:none" />');
        $('.preload').preload({
          onRequest:function(){
            $('body').append('<div class="loading">&nbsp;</div>');
          },
          onFinish: function(){
              $("#what-image").fullSizeImage('refresh');
            $('#what-image').children('img:visible').fadeOut(function(){
              $(this).remove();
            });
            $('.preload').fadeIn(function(){
              $('.preload').removeClass('preload');
              $('.loading').remove();
			 
            });
          }
        })
      }

      $('#what-image-holder .move-left').click(function(){
        if($('.selected').prev('article').size()<1){
          $('#what-we-have article:last').children('a').trigger('click');
        } else {
          $('.selected').prev('article').children('a').trigger('click');
        }
      })

      $('#what-image-holder .move-right').click(function(){
        if($('.selected').next('article').size()<1){
          $('#what-we-have article:first').children('a').trigger('click');
        } else {
          $('.selected').next('article').children('a').trigger('click');
        }
      })

      $('#what-we-have article a').click(function(){
        linkImage = $(this).attr('href');
        $('h2').html($(this).attr('rel'));
        $('.selected').removeClass('selected');
        $(this).parent().addClass('selected');
        whatWeTransition(); 
      });
      
    };

    $('.youtube-clips').css({
      'bottom': - ($('.youtube-clips li:first').height() * $('.youtube-clips li').size()),
      'display':'block'
    })

   

    $('.teasers').click(function(e){
      e.preventDefault();
      if ($('.youtube-clips').css('bottom').replace('px','') == - ($('.youtube-clips li:first').height() * $('.youtube-clips li').size())) {
        $('.youtube-clips').animate({'bottom':'38'})   
      } else {
        $('.youtube-clips').animate({
          'bottom': - ($('.youtube-clips li:first').height() * $('.youtube-clips li').size())
        });
      };

      if ($('#enquiry-form').size() > 0) {
        $('#enquiry-form').animate({
          'bottom': - ($('#enquiry-form').height())
        });
      }
    })

    $('.enquiry').click(function(e){
      e.preventDefault();
     
        $('#enquiry-form').slideToggle();

      if ($('.youtube-clips').size() > 0) {
        $('.youtube-clips').animate({
          'bottom': - ($('.youtube-clips li:first').height() * $('.youtube-clips li').size())
        });
      };
    })
	
	
		
	if ($('#our-biographies').size() > 0 || $('#what-we-content').size() > 0 || $('#kitchen').size() > 0 || $('#entertainment').size() > 0 || $('#styling').size() > 0 || $('#event-management').size() > 0 || $('#production').size() > 0 || $('#lighting').size() > 0) {
		$('#enquiry-form, .youtube-clips').hide();
		
	}
	
$('.loading').delay(3000).hide();
    $("a[rel^='prettyPhoto']").prettyPhoto({
      ie6_fallback: true,
      theme: 'light_rounded',
      default_width: 700,
      default_height: 481
    });
  })
