isIE = false;
photoIndex = -1;
$(document).ready(function () {
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie"){
			isIE = true;
		}
	
	});
	
	$("a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank').attr("title", "Opens in a new window");;
	
	$("div.scrollable").scrollable();
	
	$('.add-ajax').each(function(){
		$(this).attr('href', $(this).attr('href') + "&a=1");
	});
	
	$('.thumb-image').click(function(){
		 var url = $(this).attr("rel");
 	 	$('.large-image').hide().load(function(){
	 		$(this).fadeIn("slow");
	 	}).attr('src', url);
		/* 
         var wrap = $(".large-image").fadeTo("medium", 0.5); 
		 var img = new Image(); 
	 	 img.onload = function() { 
	        wrap.fadeTo("fast", 1); 
	        wrap.find("img").attr("src", url); 
	 	 }; 
	 	 img.src = url;
	 	*/ 
	}).filter(":first").click();

	$(".nav a").click(function(){
		$(".nav a").removeClass("selected");
		$(this).addClass("selected");
		if (jQuery.browser.msie) {
			if ($f()) {
				$f().stop();
			}
        }
		if($(this).attr("href") == "#video"){
			
			//$f().play($('#first-video').attr("rel"));
		}
		
	});

	$(".nav").tabs("div.content > div");
	
	$(".items img").click(function() { 
		$f().play($(this).attr("rel"));
	});
	//.filter(":first").click();


	$(".video-link").click(function() { 
		$f().play($(this).attr("rel"));
		return false;
	});
	
	$('.photo-nav .prev').click(function(){
		photoIndex--;
		if(photoIndex < 0){photoIndex = photos.length;}
		if(photoIndex == photos.length){photoIndex--;}
		changeLargeImage(photos[photoIndex])
	});
	
	$('.photo-nav .next').click(function(){
		photoIndex++;
		//if(photoIndex > photos.length){photoIndex = photos.length;}
		if(photoIndex > photos.length-1){photoIndex = 0;}
		changeLargeImage(photos[photoIndex]);
	}).filter(":first").click();
});

function checkEmail(email){
    if (email == "") return false;
    var expression = /^[a-zA-Z0-9\-\_\.\@]+$/;
    if (expression.test(email) && email.match(/@{1}/)) {
        return true;
    }
    return false;
}

function changeLargeImage(photoData){
   	 url = photoData["url"];
	 copy = photoData["copy"];
     
	 if ($('#main-img').attr('src') != url) {
	 	$('#main-image').hide().load(function(){
	 		$(this).fadeIn("slow");
	 		$('.photo-copy').text(copy);
	 	}).attr('src', url);
	 }
	 /*
	 $(".main-image").fadeTo("slow", 0.4, function(){
		$(".main-image").attr('src',url).bind('readystatechange load', function(){
		   	if (this.complete){
		   		$(this).fadeTo("slow", 1);
				$('.photo-copy').text(copy);
		   	} 
		});
	});
	 */
	 //var wrap = $(".main-image").fadeTo("medium", 0.5);
	 
	  /*
	 var img = new Image(); 
 	 img.onload = function() { 
        wrap.fadeTo("fast", 1); 
        wrap.find("img").attr("src", url);
   	 	$('.photo-copy').text(copy); 
 	 }; 
 	 img.src = url;
 	 */
	
}


function getVideoPlayer(width_, height_, target_id){
	if(height_ <= 400){height_ = 30;}else{height_=60;}
		$f(target_id, SERVER_URL+"/images/flowplayer-3.2.1.swf", {plugins: {
			controls:{
				bottom:20, 
        		height:height_, 
				width:width_-100,
				opacity:0.6,
				scrubberHeightRatio: 0.2,
				volumeSliderHeightRatio: 0.2,
				timeBgHeightRatio: 0.4,
        		backgroundColor: '#151515',
				buttonColor: '#252525',
				bufferColor: '#252525', 
        		backgroundGradient: 'none', 
		        fontColor: '#999999',
				progressColor: '#FFFFFF', 
        		timeColor: '#FFFFFF',
				timeBgColor: '#151515', 
        		autoHide: 'always', 
		        play:true, 
        		volume:true, 
        		mute:true, 
        		time:true, 
        		stop:false, 
        		playlist:false, 
		        fullscreen:true, 
		        scrubber: true 
			}
		}
	});
}
