// JavaScript Document

var product_bg = "images/photography/Product_Photo_0"+getRandomNumber(4)+".jpg";
var about_bg = "images/photography/About_Photo_0"+getRandomNumber(2)+".jpg";
var event_bg = "images/photography/Event_Photo_0"+getRandomNumber(2)+".jpg";
var test_bg = "images/photography/Testimonial_Photo_0"+getRandomNumber(2)+".jpg";
		
function init()
{
	$('div.cont_wrap').css({"margin-left": $(window).width()+"px"});
}
var images = new Array()
function preload() {
	for (i = 0; i < preload.arguments.length; i++) {
		images[i] = new Image()
		images[i].src = preload.arguments[i]
	}
}




function adjustImageSize(img){
	var w_w	= $(window).width(),
	w_h	= $(window).height(),
	r_w	= w_h / w_w,
	i_w	= img.width(),
	i_h	= img.height(),
	r_i	= i_h / i_w,
	new_w,new_h,
	new_left,new_top;
		
	if(r_w > r_i){
		new_h	= w_h;
		new_w	= w_h / r_i;
	}
	else{
		new_h	= w_w * r_i;
		new_w	= w_w;
	}
		
	img.css({
		width	: new_w + 'px',
		height	: new_h + 'px'
		
	});
}

function load()
{
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if(is_chrome == true){
		$('.cont').css({'font-family':'HelveticaNeueLTLight'});
	}
	
	$('#logo').stop().delay(500).animate({"opacity": "1"},3000);
	$('#menu').stop().delay(2000).animate({"opacity": "1"},2000);
	
	//SCROLL
	$('li.panel').click(function () {
		//alert($curr);
		current = $(this);
		$('#wrapper').scrollTo($(this).attr('href'),1500,{easing:'easeOutExpo'});
		adjustImageSize($('#about_bg'));
		adjustImageSize($('#product_bg'));
		adjustImageSize($('#event_bg'));
		adjustImageSize($('#test_bg'));
		
		return false;
	});
	
	$('#logo').click(function () {
		$curr= 0;
		$("li.panel").find("img:eq(2)").stop().animate({"opacity": "1"}, "slow");
		$("li.panel").find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
		$("li.panel").eq($curr).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
		$("li.panel").eq($curr).find("img:eq(2)").stop().animate({"opacity": "0"}, "slow");
		$('#wrapper').scrollTo($(this).attr('href'), 1500,{easing:'easeOutExpo'});
		$('div.cont_wrap').each(function(i)
		{
			$('div.cont_wrap').eq(i).stop().animate({"margin-left": $(window).width()+"px"}, 200, 'easeInQuart');
		});				
		return false;
	});
	
	$("#product_bg").attr("src",product_bg);
	$("#about_bg").attr("src",about_bg);
	$("#event_bg").attr("src",event_bg);
	$("#test_bg").attr("src",test_bg);	
	
}
function getRandomNumber(maxNum){
	var Random_Number = Math.ceil(Math.random()*(maxNum));
	return Random_Number;
}

function iebuttons(){

	$('#menu img').each(function(i)
	{
		var src_attr = $('#menu img').eq(i).attr('src');
		var substr = src_attr.split('/');
		var substr2 = substr[2].split('.');
		$('#menu img').eq(i).attr('src',substr[0]+"/"+substr[1]+"/ie/"+substr2[0]+".jpg");
	});
	$('#submit_reset .rollover').css({'top':'0'});
	$('#submit_reset img').each(function(i)
	{
		var src_attr = $('#submit_reset img').eq(i).attr('src');
		var substr = src_attr.split('/');
		var substr2 = substr[2].split('.');
		$('#submit_reset img').eq(i).attr('src',substr[0]+"/"+substr[1]+"/ie/"+substr2[0]+".jpg");
	});
	$('#prev_next img').each(function(i)
	{
		var src_attr = $('#prev_next img').eq(i).attr('src');
		var substr = src_attr.split('/');
		var substr2 = substr[2].split('.');
		$('#prev_next img').eq(i).attr('src',substr[0]+"/"+substr[1]+"/ie/"+substr2[0]+".jpg");
	});
	
	$('#logo').css({'width':'192px','height':'192px'});
	$('#menu').css({'margin-left':'-2px'});
	$('#.link_list li span').css({'margin-left':'-10px'});
	if(ie7 == true)
	{
		//$('#menu li').css({'margin-bottom': '-6px'});
		$('.cont').css({'font-family':'HelveticaNeueLTLight'});
		$('#prev_next .rollover').css({'top':'0px'});
		$('#submit_reset .rollover').css({'top':'0px'});
	}
	else
	{
		$('#prev_next .rollover').css({'top':'-1px'});
		$('#submit_reset .rollover').css({'top':'-1px'});
	}
}
var $curr= 0;
function rollover()
{
	$("li.panel").hover(
		function() {
			if($curr != $(this).index())
			{
				$(this).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
				//$(this).find("img:eq(0)").fadeOut('fast');
			}
		},
		function() {
			if($curr != $(this).index())
			{
				$(this).find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
				//$(this).find("img:eq(0)").fadeIn('fast');
			}
		});
	
	$('#submit_reset a').hover(
		function() {
			$(this).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
		},
		function() {
			$(this).find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
		}
	);
	
	$('#prev_next a').hover(
		function() {
			$(this).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
		},
		function() {
			$(this).find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
		}
	);
}

function active()
{
	$("li.panel").eq($curr).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
	$("li.panel").eq($curr).find("img:eq(2)").stop().animate({"opacity": "0"}, "slow");
	$("li.panel").click(
		function() {
			
			
			$("li.panel").find("img:eq(2)").stop().animate({"opacity": "1"}, "slow");
			$("li.panel").find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
			$(this).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
			$(this).find("img:eq(2)").stop().animate({"opacity": "0"}, "slow");
			$curr=$(this).index();
			$('div.cont_wrap').each(function(i)
			{
				$('div.cont_wrap').eq(i).stop().animate({"margin-left": $(window).width()+"px"}, 200, 'easeInQuart');
			});
			$('div.cont_wrap:eq('+($curr-1)+')').stop().delay(700).animate({"margin-left": "350px"}, 800, 'easeOutExpo');
		});
}

//READY
$(document).ready(function() {	
	
	preload(
	'images/photography/Home_Photo_01.jpg',
	'images/photography/Home_Photo_02.jpg',
	'images/photography/Home_Photo_03.jpg',
	'images/photography/Home_Photo_04.jpg',
	'images/photography/Home_Photo_05.jpg',
	'images/photography/Home_Photo_06.jpg',
	'images/photography/Home_Photo_07.jpg',
	'images/photography/Home_Photo_08.jpg',
	'images/nav/Logo.png',
	product_bg,
	about_bg, 
	event_bg, 
	test_bg
);		
	if(ie == true){
		iebuttons();
		applyfilter();
	}
	else
	{
		adjustImageSize($('#about_bg'));
		adjustImageSize($('#product_bg'));
		adjustImageSize($('#event_bg'));
		adjustImageSize($('#test_bg'));
	}
	
	
	repos_menu();
	
	load();
	rollover();
	slide("#menu", 25, 15, 150, .8);
	active();
	
	$('.bg').width($('.bg').width() - '15px'); 
	$('.bg').height($('.bg').height() - '15px'); 
	$(window).resize(function () {
		resizePanel();
		adjustImageSize($('#about_bg'));
		adjustImageSize($('#product_bg'));
		adjustImageSize($('#event_bg'));
		adjustImageSize($('#test_bg'));
		repos_menu();
	});	
	//hover_links();
	$("#browse").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'type'				: 'iframe',
		'overlayColor'		: '#222',
		'opacity'			: 'true',
		'overlayOpacity'	: 0.5
	});
	
	$("#service_list li a").fancybox({
		'width'				: '50%',
		'height'			: '50%',
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'overlayColor'		: '#222',
		'titlePosition'		: 'over',
		'opacity'			: 'true',
		'overlayOpacity'	: 0.5
	});
	
	$('#contact_link').click(function () {
		$curr= 5;
		$("li.panel").find("img:eq(2)").stop().animate({"opacity": "1"}, "slow");
		$("li.panel").find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
		$("li.panel").eq($curr).find("img:eq(0)").stop().animate({"opacity": "0"}, "slow");
		$("li.panel").eq($curr).find("img:eq(2)").stop().animate({"opacity": "0"}, "slow");
		$('#wrapper').scrollTo($(this).attr('href'), 1500,{easing:'easeOutExpo'});
		$('div.cont_wrap').each(function(i)
		{
			$('div.cont_wrap').eq(i).stop().animate({"margin-left": $(window).width()+"px"}, 200, 'easeInQuart');
		});		
		return false;
	});
	
	function repos_menu(){
		if(($(window).height()*0.6)< 290)
		{
			if($(window).height()>290){
				$('#nav').css({'top':($(window).height()-290)+'px'});
			}
			else if($(window).height()<290){
				$('#nav').css({'top':'0px'});
			}
		}
		else
		{
			$('#nav').css({'top':'40%'});
		}
	}
	
	$(function() {
		$("#searchForm").submit(function() {
			$form = $(this);
			$.fancybox({
				'href': $form.attr("action") + "?" + $form.serialize(),
				'type': 'iframe',
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'overlayColor'		: '#222',
				'opacity'			: 'true',
				'overlayOpacity'	: 0.5

			});
			return false;
		});
	});
	
	$('#test_cycle').cycle({
		timeout:15000,
		cleartypeNoBg: true, 
		next: '#next_cycle',
		prev: '#prev_cycle'
		
	});
	
	$("#contactform").validate({
		debug: false,
		rules: {
			topic: "required",
			name: "required",
			email: {
				required: true,
				email: true
			},
			message: "required"
		},
		messages: {
			topic: "* Required",
			name: "* Required",
			email: "* Valid Email Required.",
			message: "* Required"
		},
		submitHandler: function(form) {
			// do other stuff for a valid form
			$.post('email.php', $("#contactform").serialize(), function(data) {
				$('#results').html(data);
			});
		}
	});
	
});
jQuery(function($){
		$.supersized({
		
			//Functionality
			slideshow               :   1,		//Slideshow on/off
			autoplay				:	1,		//Slideshow starts playing automatically
			start_slide             :   1,		//Start slide (0 is random)
			random					: 	1,		//Randomize slide order (Ignores start slide)
			slide_interval          :   4000,	//Length between transitions
			transition              :   6, 		//0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
			transition_speed		:	2000,	//Speed of transition
			new_window				:	1,		//Image links open in new window/tab
			pause_hover             :   0,		//Pause slideshow on hover
			keyboard_nav            :   1,		//Keyboard navigation on/off
			performance				:	1,		//0-Normal, 1-Hybrid speed/quality, 2-Optimizes image quality, 3-Optimizes transition speed // (Only works for Firefox/IE, not Webkit)
			image_protect			:	1,		//Disables image dragging and right click with Javascript
			image_path				:	'images/', //Default image path

			
			min_width		        :   0,		//Min width allowed (in pixels)
			min_height		        :   0,		//Min height allowed (in pixels)
			vertical_center         :   1,		//Vertically center background
			horizontal_center       :   1,		//Horizontally center background
			fit_portrait         	:   1,		//Portrait images will not exceed browser height
			fit_landscape			:   0,		//Landscape images will not exceed browser width
			
			
			navigation              :   0,		//Slideshow controls on/off
			thumbnail_navigation    :   0,		//Thumbnail navigation
			slide_counter           :   0,		//Display slide numbers
			slide_captions          :   0,		//Slide caption (Pull from "title" in slides array)
			slides 					:  	[		//Slideshow Images
												{image : 'images/photography/Home_Photo_01.jpg'},
												{image : 'images/photography/Home_Photo_02.jpg'},
												{image : 'images/photography/Home_Photo_03.jpg'},
												{image : 'images/photography/Home_Photo_04.jpg'},
												{image : 'images/photography/Home_Photo_05.jpg'},
												{image : 'images/photography/Home_Photo_06.jpg'},
												{image : 'images/photography/Home_Photo_07.jpg'},
												{image : 'images/photography/Home_Photo_08.jpg'}
												
										]
		}); 
	});
	

function resizePanel() {

	width = $(window).width();
	height = $(window).height();

	mask_height = height * $('.item').length;
		
	$('#debug').html(width  + ' ' + height + ' ' + mask_height);
	
	$('#wrapper, .item').css({width: width, height: height});
	$('#mask').css({width: width, height: mask_height});
	$('#wrapper').scrollTo($("li.panel").eq($curr).attr('href'), 0);

}

function hover_links() {

	$('.link_list li').hover(
		function() {
			$(this).css({'color':'#FFF'});
			$(this).find('span').css({'color':'#FFF'});
		},
		function() {
			$(this).css({'color':'#FFF'});
			$(this).find('span').css({'color':'#CC2222'});
		}
	);
}
	
function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
	// creates the target paths
	var list_elements = "li.panel";
	// initiates the timer used for the sliding animation
	var timer = 0;
	// creates the slide animation for all list elements 
	$(list_elements).delay(2000).each(function(i)
	{
		// margin left = - ([width of element] + [total vertical padding of element])
		//$(this).css("margin-left","500px");
		// updates timer
		timer = (timer*multiplier + time);
		
		$(this).animate({ marginLeft: "15px" }, timer);
		$(this).animate({ marginLeft: "0" }, timer);
		$(this).find("img:eq(0)").stop().animate({"opacity": "1"}, "slow");
		$(this).find("img:eq(1)").stop().animate({"opacity": "1"}, "slow");
		$(this).find("img:eq(2)").stop().animate({"opacity": "1"}, "slow");
	});
}

function resetform(fReset)
{
	$('#topic').attr("value","");
	$('#name').attr("value","");
	$('#email').attr("value","");
	$('#message').attr("value","");
	if(fReset == true){
		$('#results').html("");
	}
}

function submitform()
{
	$('#contactform').submit();
}

function applyfilter()
{
	$('#nav img').each(function(i)
	{
		var src_attr = $('#nav img').eq(i).attr('src');
		$('#nav img').eq(i).attr('style',"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src_attr+"');");
	});
}


