// JavaScript Document
// Developer: PersianIcon
$(document).ready(function()
{
	tooltip();
	//image effect
	$(".pimg").fadeTo("normal", 0.8)
	$(".pimg").hover(function(){
	$(this).fadeTo("normal", 1.0);
	},function(){
		$(this).fadeTo("normal", 0.7);
	});

	//news
	$('.newstitle').bind('click', function(e) {
		var nb = $('.newsbody');
		$('.newsbody').slideUp(390);
		$('.newstitle').css("color","#757575");
		$(this).next('.newsbody').slideToggle(400);
		$(this).css("color","#f00");
	});
 
});

//ajax gallery
function showImage(query,img,loading)
{
	if(img != 0){
	if(loading == 1){ $('#AjaxLoad').show(); }
	$('#AjaxContent').load('/ajax?type=json&'+query, function() {
		$('#AjaxLoad').hide();
		$('#AjaxContent').fadeIn(250);
	});

	$(".gallery-box *").css('border-color','#fff');
	$("#img"+img).css('border-color','#50b1f4');
	$('#MainDiv').hide(690);
	$('#Ajax').show(700);

	$('.AjaxClose').bind('click', function(e) {
		$('#MainDiv').show(300);
		$('#Ajax').hide(300);
		window.setTimeout(function(){
			showIt("img"+img);
			$('#AjaxContent').hide();
			$('#AjaxLoad').show();
		}, 310);
	});
	}else{
		$("#gImage").hide();
		$("#gDiv").html('<div id="gEnd">The End<\/div>');
	}
}

function showIt(elID)
{
	var el = document.getElementById(elID);
	el.scrollIntoView(true);
}

// language dropdown
$(document).ready(function(){
	$(".dropdown img.flag").addClass("flagvisibility");
	$(".dropdown dt a").click(function() {
	$(".dropdown dd ul").toggle();
	return false;
	});

$(".dropdown dd ul li a").click(function() {
	var text = $(this).html();
	$(".dropdown dt a span").html(text);
	$(".dropdown dd ul").hide();
	$("#result").html("Selected value is: " + getSelectedValue("sample"));
});

function getSelectedValue(id) {
	return $("#" + id).find("dt a span.value").html();
}

$(document).bind('click', function(e) {
	var $clicked = $(e.target);
	if (! $clicked.parents().hasClass("dropdown"))
		$(".dropdown dd ul").hide();
});

$("#flagSwitcher").click(function() {
	$(".dropdown img.flag").toggleClass("flagvisibility");
});
});
//tooltip
this.tooltip = function(){	
/* CONFIG */
  xOffset = 8;
  yOffset = 10;		
/* END CONFIG */
$("a.tooltip").hover(function(e){											  
  this.t = this.title;
  this.title = "";
  $("body").append("<p id='tooltip'>"+ this.t +"</p>");
  $("#tooltip")
	  .css("top",(e.pageY - xOffset) + "px")
	  .css("left",(e.pageX + yOffset) + "px")
	  .fadeIn(500);
},
function(){
  this.title = this.t;		
  $("#tooltip").remove();
});	
$("a.tooltip").mousemove(function(e){
  $("#tooltip")
	  .css("top",(e.pageY - xOffset) + "px")
	  .css("left",(e.pageX + yOffset) + "px");
});			
};
//Home
function slideSwitch() {
    var $active = $('#slideshow DIV.active');
    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()",8000 );
});
// over
$(document).ready(function(){
$('.boxgrid.slidedown').hover(function(){
	$(".cover", this).stop().animate({top:'-260px'},{queue:false,duration:300});
}, function() {
	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});
});
//Horizontal Sliding
$('.boxgrid.slideright').hover(function(){
	$(".cover", this).stop().animate({left:'325px'},{queue:false,duration:300});
}, function() {
	$(".cover", this).stop().animate({left:'0px'},{queue:false,duration:300});
});
//Diagnal Sliding
$('.boxgrid.thecombo').hover(function(){
	$(".cover", this).stop().animate({top:'260px', left:'325px'},{queue:false,duration:300});
}, function() {
	$(".cover", this).stop().animate({top:'0px', left:'0px'},{queue:false,duration:300});
});
});
