
function getPhotoImage(path) {
	sz = 0;
	htm = '<ul id="vertical-carousel" class="jcarousel-skin-tango">';

	$('div[hlist="'+path+'"]').children('div[vlist]').each(function(index, element) {
		if(sz == 0) { getMainImage($(this).attr('vlist')); }
		htm += '<li><span onclick="return getMainImage('+$(this).attr('vlist')+')" path="'+$(this).attr('vlist')+'" style="cursor: pointer;">'
		+ '<img width="115px" height="87px" border="0" src="upload/images/'+$(this).attr('src')+'" /></span></li>';
		sz ++;
    });

	htm += '</ul>';
	
	$('#vertical-carousel').closest('div.jcarousel-skin-tango').replaceWith(htm);
	$('#vertical-carousel').jcarousel({vertical: true, scroll: 6});
	
	return false;
}

function getMainImage(path) {
	var elm = $('div[vlist="'+path+'"]');
	var htm = '<a href="#" id="main_photo_img" path="'+path+'" style="cursor: default;"><img src="upload/images/'+elm.attr('image')+'" border="0" class="reflect" style="cursor: default;"/></a>';

	$('#main_photo_img').replaceWith(htm);
	$('#main_photo_img').children('img').load( function () {
		Reflection.add($(this)[0], { height: null, opacity : null});
		n_href = 'email_friend_photo.php?path='+php_urlencode('/photos.php?id='+elm.attr('gal_id')+'&id_main='+path);

		$('a.email_friend2').attr('href', n_href);
		$(".shadow").colorbox({width:"708", height:"640", opacity:"0.0", iframe:true});
	});
	
	$('a[name=fb_share]').attr('href', 'http://www.facebook.com/sharer.php?u='+php_urlencode('http://shakila.com/upload/images/'+elm.attr('image')));
		
	return false;
}

var flag = "";

function getPlayer(i) {
	if(flag != 'i') { $("#pos_"+flag).slideUp(); }
	if($("#pos_"+i).is(":hidden")) { $("#pos_"+i).slideDown("1500"); }
	else { $("#pos_"+i).slideUp(); }
	flag = i;
	return false;
}

function getVideoImage(path) {
	sz = 0;
	htm = '<ul id="vertical-carousel" class="jcarousel-skin-tango">';

	$('div[hlist="'+path+'"]').children('div[vlist]').each(function(index, element) {
		if(sz == 0) { getMainVideo($(this).attr('vlist')); }
		htm += '<li><span onclick="return getMainVideo('+$(this).attr('vlist')+')" style="cursor:pointer;">'
		+ '<img width="115px" height="87px" border="0" src="'+$(this).attr('src')+'" /></span></li>';
		sz ++;
    });

	htm += '</ul>';
	
	$('#vertical-carousel').closest('div.jcarousel-skin-tango').replaceWith(htm);
	$('#vertical-carousel').jcarousel({vertical: true, scroll: 6, size: sz});

	return false;
}

function getMainVideo(path) {
	var elm = $('div[vlist="'+path+'"]');
	
	n_htm = '<object width="550" height="412" name="main_big_video" id="main_big_video">'
	+ '<param name="movie" value="'+elm.attr('video')+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'
	+ '<embed wmode="transparent" src="'+elm.attr('video')+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="550" height="412"></embed></object>';
	$('#main_big_video').html(n_htm);
	
	n_href = 'email_friend.php?path='+php_urlencode('/videos.php?id='+elm.attr('gal_id')+'&id_main='+path);
	$('a.email_friend2').attr('href', n_href);
	$('a[name=fb_share]').attr('href', 'http://www.facebook.com/sharer.php?u=' + elm.attr('video_share'));
	
	return false;
}

function php_urlencode (str) {
	str = escape(str);
	return str.replace(/[*+\/@]|%20/g,
	function (s) {
	switch (s) {
	case "*": s = "%2A"; break;
	case "+": s = "%2B"; break;
	case "/": s = "%2F"; break;
	case "@": s = "%40"; break;
	case "%20": s = "+"; break;
	}
	return s;
	});
}

$(document).ready(function(){
	$("#sub_id").click(function(){
		var contact_name = $("#contact_name").val();
		var contact_email = $("#contact_email").val();
		var contact_state = $("#contact_state").val();
		var contact_msg = $("#contact_msg").val();
		
		errors = false; str = "";
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(reg.test(contact_email) == false) { errors = true; }
		if(contact_msg == "") { errors = true; }
		if(contact_state == "") { errors = true; }
		if(contact_name == "") { errors = true; }
		
		if(errors) {
			$('#mes_err').html("<span class = 'errorMsg'>Some of the fields are not entered correctly !</span>");
		   return false;
		} else {
			var datastr ="contact_email=" + contact_email + "&contact_name=" + contact_name + "&contact_state=" + contact_state + "&contact_msg=" + contact_msg;
			send(datastr);
			return false;
		}
	});
})

function send(datastr){
	$.ajax({
		type: "POST",
		url: basepath+"valid_contact.php",
		data: datastr,
		cache: false,
		success: function(html) {
			if(html.msg=="Invalid Email"){
				$("#contact_email").val(html.contact_email);
				$("#contact_name").val(html.contact_name);
				$("#contact_state").val(html.contact_state);
				$("#contact_msg").val(html.contact_msg);
				$('#mes_err').html("<span class = 'successMsg'>Invalid Email! </span>");
			} else {
				$("#contact_email").val("");
				$("#contact_name").val("");
				$("#contact_state").val("");
				$("#contact_msg").val("");
				$('#mes_err').html("<span class = 'successMsg'>Your request has been submitted successfully! </span>");
			}
		}
	});
}

/* Photos Rotate */

function photosPrev() { 
	var path = $('a#main_photo_img').attr('path');
	var yy = $('ul#vertical-carousel').position().top * -1;
	var bb; var i = 0;
	
	$('ul#vertical-carousel li').each(function(index, element) {
		if(path == $(this).find('span').attr('path')) { bb.click(); return false; }
		else { bb = $(this).find('span'); i++; }
    });
	
	if(yy > ((i-1) * 99)) { 
		$('div.jcarousel-container-vertical div.jcarousel-prev').click(); 
	}
}

function photosNext() {
	var path = $('a#main_photo_img').attr('path');
	var yy = $('ul#vertical-carousel').position().top * -1;
	var bb = false; var i = 0;
	
	$('ul#vertical-carousel li').each(function(index, element) {
		if(bb) { $(this).find('span').click(); return false; }
		if(path == $(this).find('span').attr('path')) { bb = true; }
		i++;
    });

	if(yy < ((i-5) * 99)) { 
		$('div.jcarousel-container-vertical div.jcarousel-next').click(); 
	}
}


