﻿$(document).ready(function(){
    $('.Nav ul li').eq($('#mainNav').val() - 1).find('a').addClass("on");
    $('.subNav').append('<div class="eyeCandy"></div>');
    if ($('.subNav ul').length > 0){
        $('.subNav ul li').eq($('#subNav').val() - 1).find('a').addClass("on");
        //add eyeCandy image to subnav
        //$('.subNav').append('<img src="/images/subNav_move_' + $('.subNav').parent().attr('class') + '.png" class="eyeCandy" />');
        
        var ecHome = $('.subNav ul li').eq($('#subNav').val() - 1).find('a').position().left + 7
        //position eyeCandy to current subpage position
        $('.eyeCandy').css('left',ecHome + 'px');
        
        $('.subNav ul li a').hover(
            function(){
                $('.eyeCandy').stop().animate({left:($(this).position().left + 7) + 'px'}, 500)
            },
            function(){
                $('.eyeCandy').stop().animate({left:ecHome + 'px'}, 500)
            }
        );
    }
    /*photoGallery*/
        $('.photoGallery').before($('.galImg').clone().removeClass('galImg').addClass('thumb'));
        $('.photoGalleryContainer h1').before('<div style="clear:both;"></div>');
        $('.photoGalleryContainer h1').text($('.galImg').eq(0).attr('title'));
        
        $('.thumb').thumbs();
        $('.thumb').thumbsImg();
        $('.thumb-img').eq(0).addClass('on');
        
        $('.galImg').eq(0).clone().removeClass('galImg').addClass('galImgTemp').css('display','block').appendTo($('.photoGallery'));
        $('.photoGalleryContainer p').text($('#pTitle').val());
        
        var index = 0;
        
        $('.thumb-img').click(function(){
            index = $('.thumb-img').index(this);           
            switchImg();             
        });
        function switchImg(){        
        $('.thumb-img').removeClass('on');
        $('.thumb-img').eq(index).addClass('on');
        $('.photoGallery')
            .children('img')
                .fadeOut(500,function(){
                    $(this).remove();
                    //alert($('.photoGallery').children('img').length);
                }).end()
            .append($('.galImg').eq(index).clone().removeClass('galImg').addClass('galImgTemp').css({position:'absolute',right:'0px',top:'0px',display:'none'}))            
            .children('img:last')
                .fadeIn(500,function(){
                    $('.photoGallery').height($(this).height());
                    $('.photoGalleryContainer').width($(this).width());
                }); 
        $('.photoGalleryContainer h1').text($('.galImg').eq(index).attr('title'));        
                //alert($('.galImg').length);
    }
        $("#quotes").quotator({
        	speed : 5000,
    	    json : "../scripts/quotator_quotes.js"
	        });            

    /*photoGallery*/
	$("a.fancy").fancybox({
				'zoomSpeedIn':	500, 
				'zoomSpeedOut':	500, 
				'overlayShow':	true,
				'overlayOpacity': .8,
				'frameWidth': 340,
				'frameHeight': 260
			});
			
			for(i=0;i<$('.openVideo').length;i++){
			    $('.openVideo').eq(i).attr('href', '#video');
			}
			
			var videoName;
			
            function video(){ 
                $('#objContent').empty();
				if(videoName.indexOf(".flv") > 0){
	                $('#objContent').append('<embed type="application/x-shockwave-flash" src="Media/Videos/mediaplayer.swf" style="" quality="high" wmode="opaque" flashvars="file=' + videoName + '&amp;autostart=true&amp;controlbar=over&amp;displaywidth=320&amp;displayheight=240&amp;frontcolor=0x404040&amp;lightcolor=0x808080" width="320" height="240">');
				}else{
					$('#objContent').append('<EMBED TYPE="application/x-mplayer2" SRC="' + videoName + '" NAME="MediaPlayer" WIDTH="320" HEIGHT="240" ShowControls="0" ShowStatusBar="0" ShowDisplay="0" autostart="1"> </EMBED>');
				}
            }
            $('.openVideo').mousedown(function(){
                videoName = $(this).attr('video');
                video();
            });
});


/*
 *
 * Copyright (c) 2006 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

/*
 * Converts image and link elements to thumbnails
 *
 * @name     jThumb
 * @author   Joan Piedra (http://www.joanpiedra.com)
 * @example  $("a.thumb, img.thumb").thumbs();
 *
 */
jQuery.fn.thumbs = function()
{
	return $(this)
	    .css('display','block')
	    .wrap('<div class="thumb-img"><div class="thumb-inner">');// + '</div><div class="thumb-strip"></div><div class="thumb-zoom"></div></div>');
}

/*
 * Absolute positions the image in the middle of the thumbnail frame
 *
 * @name     jThumbImg
 * @author   Joan Piedra (http://www.joanpiedra.com)
 * @example  $("a.thumb img, img.thumb").thumbsImg();
 *
 */
jQuery.fn.thumbsImg = function()
{
	return this.each(
		function()
		{
			/*jQuery(this).css('position','absolute');
			jQuery(this).css('left', '-' + ( parseInt( $(this).width() ) / 2 ) + 'px' );
			jQuery(this).css('top', '-' + ( parseInt( $(this).height() ) / 2 ) + 'px' );
			jQuery(this).css('margin-left', '50%' );
			jQuery(this).css('margin-top', '50%' );
			*/
			jQuery(this)
			    .width(50*(jQuery(this).width()/jQuery(this).height()))
			    .height(50);
			    //alert(jQuery(this).width());
		}
	)
}