// JavaScript Document
$(document).ready(function(){
	$("#sign_up #email").focus(function(){
			if($("#email").val()=="Enter your Email Address")
				$("#email").val('');
	});
	$("#sign_up #email").focusout(function(){
		if($("#email").val()=="")
			$("#email").val('Enter your Email Address')	
	});
		// transition effect
		style = 'easeOutQuart';
		$('.caption').hide();
		// if the mouse hover the image
		$('.photo').hover(
			function() {
				//display heading and caption
				$(this).children('div:first').stop(false,true).animate({top:0},{duration:200, easing: style});
				$(this).children('div:last').stop(false,true).animate({bottom:0},{duration:200, easing: style});
				var current_div=$(this).attr("id")
				var div_id=current_div.replace("photo_","");
				$("#deal_title_"+div_id).hide();
				$("#photo_"+div_id+" .caption").show();
			},

			function() {
				//hide heading and caption
				$(this).children('div:first').stop(false,true).animate({top:-50},{duration:200, easing: style});
				$(this).children('div:last').stop(false,true).animate({bottom:-50},{duration:200, easing: style});
				var current_div=$(this).attr("id")
				var div_id=current_div.replace("photo_","");
				$("#deal_title_"+div_id).show();
				$("#photo_"+div_id+" .caption").hide();
			}
		);
})
	
function change_status(id)
{
	var change_status=$("#table_name").val();
	
	var status_image='enable';
	
	var ok=confirm("Are you sure to change a status?")
		if(!ok)
			return false;
	$.ajax({ type: "POST",url: "cge_status",async: true,data: "id="+id+"&change_status="+change_status, success: function(data)
			{	
				if(data==1)
					status_image="enable";
				else
					status_image="disable";
					
				$("#status_change_"+id).attr("src","/css/img/"+status_image+".png")
			}
		  });
}

function delete_record(id)
{
	var change_status=$("#table_name").val();
	
	var status_image='enable';
	
	var ok=confirm("Are you sure to Delete this record?");
		if(!ok)
			return false;
			
	$.ajax({ type: "POST",url: "delete_record",async: true,data: "id="+id+"&delete_record="+change_status, success: function(data)
			{	
				if(data!=0)
					$("#row_id_"+id).remove();
				else
					alert("Error");
			}
		  });
}

function show_tabs(cur_title)
{
	$("."+cur_title+" .boxcontent").css("display","block");
	
	var class_name=$("."+cur_title+" .boxtitle a").attr("class");
	
	if(class_name=="closed")
			$("."+cur_title+" .boxtitle a").removeClass("closed");
	else
	$("."+cur_title+" .boxtitle a").addClass("closed");	
}
function custom_form_element()
{
var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
inputs = document.getElementsByTagName("select");
for(a = 0; a < inputs.length; a++) {
		if(inputs[a].className == "styled") {
			option = inputs[a].getElementsByTagName("option");
			active = option[0].childNodes[0].nodeValue;
			textnode = document.createTextNode(active);
			for(b = 0; b < option.length; b++) {
				if(option[b].selected == true) {
					textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
				}
			}
			span[a] = document.createElement("span");
			span[a].className = "select";
			span[a].id = "select" + inputs[a].name;
			span[a].appendChild(textnode);
			inputs[a].parentNode.insertBefore(span[a], inputs[a]);
			if(!inputs[a].getAttribute("disabled")) {
				inputs[a].onchange = Custom.choose;
			} else {
				inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
			}
		}
	}
	document.onmouseup = Custom.clear;

}
$(function(){
	// Slider
	$('#slider').slider({
		range: true,
		min: 5,
		max: 1199, 
		values: [5, 1199],
		slide: function( event, ui ) {
			$("#price_value").html("$"+ui.values[ 0 ] + " - $"+ ui.values[ 1 ]);
			//alert(ui.values[ 0 ] + "% - " + ui.values[ 1 ])
			list_deals();
		}
	});
	$('#discount_slider').slider({
		range: true,
		min: 26,
		max: 88, 
		values: [26, 88],
		slide: function( event, ui ) {
			$("#discount_slider_value").html(ui.values[ 0 ] + "% - "+ ui.values[ 1 ]+" %");
			//alert(ui.values[ 0 ] + "% - " + ui.values[ 1 ])
			list_deals();
		}
	});
	$("#time_slider").slider({
		range: true,
		min: 0,
		max: 16, 
		values: [0, 16],
		slide: function( event, ui ) {
			$("#time_slider_value").html(ui.values[ 0 ] + " days - "+ ui.values[ 1 ]+" days");
			//alert(ui.values[ 0 ] + "% - " + ui.values[ 1 ])
			list_deals();
		}
	});
		
});

function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}
function count_down_timer(div_id,date_detail)
{
	$('#clsDeal_Time_'+div_id).countdown({
	until: new Date(date_detail+" +0000"),
	format: 'dHMS',
	layout:'<ul class="clearfix"><li><p>{dn}<p>DAYS</p></li>'+'<li><p>{hn}</p><p>HRS</p></li>'+'<li><p>{mn}</p><p>MINT</p></li> '+'<li class="clsDeal_Last_Time"><p>{sn}</p><p>SEC</p></li>'+'</ul>',
	expiryText:"Expired"
	});
}
function sample()
{
	alert("caleed");
}


