﻿function showShare() {
	$("#share").dialog('open');
}

function hideShare() {
	$("#share").dialog('close');
}

function showSubscribe() {
	$("#subscribe").dialog('open');
}

function hideSubscribe() {
	$("#subscribe").dialog('close');
}

function showEmail(entryId) {
	$("div.emailform").load("/include/tellafriend/" +  entryId, '', function(){
		$("#email").dialog('open');
	});
}

function hideEmail() {
	$("#email").dialog('close');
}

function showShareNotAvailable() {
	if ($.browser.msie) {
		$("div.sharetemp").css("display", "inline");
	} else {
		$("div.sharetemp").css("display", "inline").animate( { opacity: 0.88 }, 1000);
	}
}

function showRecommend() {
	$("#recommend").dialog('open');
	//newEmail = window.open('mailto:'+'share@farm.sg'+'?subject=L.C.D : I like to recommend a friend'+'&body=Please suggest a friend who should be featured on FARM\'s Local Creative Directory. This could be someone you know well or someone you have often seen and always wondered about. Provide as much of the following information about the person as you can. Thank you very much!<br/><br/>Name: <br/><br/>Website: <br/><br/>How can we contact him or her?');
}

function hideRecommend() {
	$("#recommend").dialog('close');
}

// when everything has loaded. Need to be before document.ready
/*
$(window).load(function () {
	$('div.item div.pictures img').fadeIn(1500);
	// fading cycling images
	$('.pictures').cycle({ 
		fx:     'fade', 
		timeout: 1000,
		cleartype: true
	});
});
*/

// when the DOM is ready...
$(document).ready(function() {	
	
	$('div.item div.pictures img').fadeIn('1500');
	
	$('.pictures').cycle({ 
		fx:     'fade', 
		timeout: 1000,
		cleartype: true
	});
	
	//search - remove the watermark
	$("#cse-search-box input[name=q]")
		.css("background", "transparent")
		.css("border", "none")
		.val('Search');
	
	$("#cse-search-box input[name=q]").blur(function(){
		$(this).css("background", "transparent");
		if ($(this).val() == ""){
			$(this).val('Search');
		}
	});
	
	$("#cse-search-box input[name=q]").focus(function(){
		$(this).css("background", "transparent");
		if ($(this).val() == "Search"){
			$(this).val('');
		}
	});
	
	// menu effects
	$("div.menu div.section").not(".current").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
			$(this).removeClass("click"); 
		}
	);
	
	$("div.menu div.section").mouseup(function(){
      $(this).removeClass("click"); 
    })
	
	$("div.menu div.section").mousedown(function(){ 
      $(this).addClass("click");
    });

	//squares effects
	$(".item").hover(
		function () {
			$(this).addClass("selected");
			// fix for IE cleartype
			//$(this).find(".details").fadeIn("normal", function(){if ($.browser.msie){this.style.removeAttribute('filter');}});
			$(this).find(".pictures").fadeOut("normal");
			if ($.browser.msie) {
				$(this).find(".details").css('display', 'block');
			} else {
				$(this).find(".details").fadeIn("normal");
			}
		}, 
		function () {
			$(this).removeClass("selected");
			$(this).find(".pictures").fadeIn("normal");
			if ($.browser.msie) {
				$(this).find(".details").css('display', 'none');
			} else {
				$(this).find(".details").fadeOut("normal");
			}
		}
   );
   
	// subscribe popup
	$("#subscribe").dialog({
		autoOpen : false,
		bgiframe: true,
		height: 450,
		width: 850,
		modal: true,
		resizable: false,
		draggable: false
	});
	
	// subscribe input box effect
	$('input#subscribeEmailAddress').blur(function(){
		if ($(this).val() == ""){
			$(this).val('Email Address');
		}
	});
	
	$("input#subscribeEmailAddress").focus(function(){
		if ($(this).val() == "Email Address"){
			$(this).val('');
		}
	});
	
	// slide show for details page
	$('.picturedetails').cycle({ 
		fx:     'fade', 
		timeout: 3000,
		speed: 3000,
		pause: true,
		containerResize: false,
		slideExpr: 'img'
	});
	
	// share popup
		$("#share").dialog({
		autoOpen : false,
		bgiframe: true,
		height: 450,
		width: 850,
		modal: true,
		resizable: false,
		draggable: false
	});
	
	// email popup
	$("#email").dialog({
		autoOpen : false,
		bgiframe: true,
		height: 450,
		width: 850,
		modal: true,
		resizable: false,
		draggable: false
	});
	
	// email popup
	$("#recommend").dialog({
		autoOpen : false,
		bgiframe: true,
		height: 450,
		width: 850,
		modal: true,
		resizable: false,
		draggable: false
	});
});