﻿

Cufon.replace('h1,h2,h3, h3 a',{});	


function playerFades() {
				
			
			//$("#zoom").css({'opacity':'0.7'});
			 
				
			jQuery("a[rel^='prettyPhoto']").prettyPhoto();

			jQuery("#resumeButton").fadeTo("slow", 0.4);
			
			
			jQuery("#resumeButton").click(function(){
			jQuery(this).stop().fadeTo("medium", 0.4);
			jQuery("#pauseButton").stop().fadeTo("slow", 1.0); 
			});
			
			
		   $(".zoom").css({'opacity':'0'});
			jQuery(".preloader, .preloader_visible,.image-wrap").hover(function(){
			jQuery("span",this).show(); 
			jQuery(this,"img").stop().fadeTo("medium", 0.6);
			jQuery(".zoom",this).stop().fadeTo("medium", 1);
			},function(){
			jQuery(this,"img").stop().fadeTo("medium", 1);
			jQuery("span",this).hide(); 
			
			});
			
			
			jQuery("#pauseButton").click(function(){
			jQuery(this).stop().fadeTo("medium", 0.4);
			jQuery("#resumeButton").stop().fadeTo("slow", 1.0);
			});
			
			
			$("#nav li a span").css({'opacity':'0.6'});
			jQuery("#nav li a span").hover(function(){
			jQuery(this).stop().fadeTo("medium", 0);
			
			},function(){
			jQuery(this).stop().fadeTo("fast", 0.6); 
			
			});
			
						
			$('.slided span').show();
			jQuery(".slided span").stop().fadeTo(0, 0);
					
		
			
			

			};

jQuery(document).ready(function(){
										  
		
		  
		jQuery('#ajaxcontent #postPagination a').live('click', function(e){
		e.preventDefault();
		var link = jQuery(this).attr('href');
		jQuery('#ajaxcontent').fadeOut(200,stopCycle).load(link + ' #ajaxloader', 
		function(){jQuery('#ajaxcontent').fadeIn(200,Cufon.refresh), hoverbutton(); startCycle(); playerFades();prettyPhoto.init(); } );
		});								  
										  
		jQuery('#gallerycycle').cycle({
        fx: 'fade',
        speed:300,
		  easing: 'easeInOutQuad',
		  cleartype:  1,
		  pause:0,
        timeout: 0,
        pager:  '#gallerynav'
		  
       
		});
		
		var $home_slider_effect = jQuery("meta[name=home_slider_effect]").attr('content');
		var $home_slider_timeout = jQuery("meta[name=home_slider_timeout]").attr('content');
		
		 $('#slideshow img:first').fadeIn(1000, function() {	 
		jQuery('#slideshow').cycle({
        fx: $home_slider_effect,
        speed:300,
		  easing: 'easeInOutQuad',
		  cleartype:  1,
		  //pause:1,
        timeout: $home_slider_timeout,
        next: '.slideshow-next',
		  prev: '.slideshow-prev'
		});
		});
										  
			startCycle();
			
			playerFades();
			
			hoverbuttonReverse();	
	
			
					
			jQuery("#resumeButton, #pauseButton, .zoomButton, .showTip, .social li a, #homebutton a, .styleswitch").simpletooltip();
			
			
			jQuery("a[rel^='prettyPhoto']").prettyPhoto();
			
			jQuery(".social li a").css({'opacity':'0.7'});
							  
			// Adds hover-function for buttons exept on IE
			if(!jQuery.browser.msie){
					hoverbutton();
				}  
				
				
			$("#primary-menu ul li.homelink a").css({'opacity':'0.6'});
			jQuery("#primary-menu ul li.homelink a").hover(function(){
			jQuery(this).stop().fadeTo("slow", 0.8); 
			},function(){
			jQuery(this).stop().fadeTo("slow", 0.6);
			});
			
			$("#s").css({'opacity':'0'});
			jQuery("#searchform #searchsubmit, #s:hidden ").hover(function(){
			jQuery(".socialmedia").hide();																				
			jQuery("#s").show().stop().fadeTo("slow", 1);
			});
			
			jQuery("#searchform").hover(function(){
			},function(){
			jQuery("#s").stop().fadeTo("slow", 0).hide();
			jQuery(".socialmedia").show();
			//jQuery("#s").hide();
			});
			
			
			
			
			
			
			
			$("#homebutton a").css({'opacity':'0.9'});
			jQuery("#homebutton a").hover(function(){
			jQuery(this).stop().fadeTo("slow", 1); 
			},function(){
			jQuery(this).stop().fadeTo("slow", 0.9);
			});
			
			//Alex - click pe imaginile din home_slideshow
			$("#slideshow").click( function( eventObj ) {
				var x = eventObj.pageX - this.offsetLeft;
				var y = eventObj.pageY - this.offsetTop;
				
				var current_id = $(this).attr("id");
				$("#slideshow").children().each(function(index, elem) { 
						var $element = $(elem);
						if ($element.attr('class') == "slideshow-slide")
						{
							//daca in style gasesc display:block, ma uit in copii si iau la img, src-ul
							//stiind src-ul pun zonele de click
							if (($element.attr('style')).search("display: block") != "-1")
								$element.children().each(function(index2, elem2) { 
									if ($(elem2).attr('id') == "slideshow_image")
										//if ($(elem2).attr('src') == "http://www.artsociety.ro/wp-content/uploads/2011/01/11.jpg")
										//{
										$("#slideshow").cycle('pause');
										//if ((x >= 55 && x <= 203) && (y>=65 && y<=188))
										//$.prettyPhoto.open('http://www.artsociety.ro/images/GrupulCelor4/1.jpg','','Francisc Șirato - La gherghef');
										images = ['http://www.artsociety.ro/images/GrupulCelor4/1.jpg','http://www.artsociety.ro/images/GrupulCelor4/2.jpg','http://www.artsociety.ro/images/GrupulCelor4/3.jpg','http://www.artsociety.ro/images/GrupulCelor4/4.jpg','http://www.artsociety.ro/images/GrupulCelor4/5.jpg','http://www.artsociety.ro/images/GrupulCelor4/6.jpg','http://www.artsociety.ro/images/GrupulCelor4/7.jpg','http://www.artsociety.ro/images/GrupulCelor4/8.jpg','http://www.artsociety.ro/images/GrupulCelor4/9.jpg','http://www.artsociety.ro/images/GrupulCelor4/10.jpg','http://www.artsociety.ro/images/GrupulCelor4/11.jpg','http://www.artsociety.ro/images/GrupulCelor4/12.jpg'];
										descriptions = ['Francisc Șirato - La gherghef','Francisc Șirato - Bluza albă','Ștefan Dimitrescu - Pereche de turci', 'Ștefan Dimitrescu - Autoportret', 'Ștefan Dimitrescu - Târg la Săliște', 'Nicolae Tonitza - Natură moartă', 'Nicolae Tonitza - Nud', 'Oscar Han - Sf. Francisc', 'Oscar Han - Eva', 'Ștefan Dimitrescu - Mama cu copii', 'Ștefan Dimitrescu - Balcic', 'Nicolae Tonitza - Zi tristă la Balcic']
										titles = ['','','','','','','','','','','',''];
										images_with_offset = new Array();
										descriptions_with_offset = new Array();
										url = "";
										url = $(elem2).attr('src');
										noOfClickedPhoto = 0;
										
										if (url != undefined)
										{
											//trebuie sa scot string-ul de dupa ultimul / si inaintea urmatorului .
											switch (url.substring(url.lastIndexOf("/")+1, url.lastIndexOf(".")))
											{
												case "12":
													noOfClickedPhoto = 12;
													break;
												case "111":
													noOfClickedPhoto = 11;
													break;
												case "10":
													noOfClickedPhoto = 10;
													break;
												case "91":
													noOfClickedPhoto = 9;
													break;
												case "8":
													noOfClickedPhoto = 8;
													break;
												case "7":
													noOfClickedPhoto = 7;
													break;
												case "6":
													noOfClickedPhoto = 6;
													break;
												case "5-900x400":
													noOfClickedPhoto = 5;
													break;
												case "4":
													noOfClickedPhoto = 4;
													break;
												case "3":
													noOfClickedPhoto = 3;
													break;
												case "2":
													noOfClickedPhoto = 2;
													break;
												case "11":
													noOfClickedPhoto = 1;
													break;
												
											}
											
											for (i=0 ; i<=11 ; i++)
											{
												if ((i+noOfClickedPhoto)%12 == 0)
												{
													images_with_offset[i] = 'http://www.artsociety.ro/images/GrupulCelor4/' + 12 + '.jpg';
													descriptions_with_offset[i] = descriptions[11];
												}
												else
												{
													images_with_offset[i] = 'http://www.artsociety.ro/images/GrupulCelor4/' + (i+noOfClickedPhoto)%12 + '.jpg';
													descriptions_with_offset[i] = descriptions[(i+noOfClickedPhoto)%12-1];
												}
											}
											$.prettyPhoto.open(images_with_offset,titles,descriptions_with_offset);
										}
								});
						}
					});
			});
			//End -> Alex - click pe imaginile din home_slideshow
	});


function hoverbutton(){
		jQuery(".btn, #submitbutton, #submit").hover(function(){
			jQuery(this).stop().fadeTo("medium", 0.6);
			},function(){
			jQuery(this).stop().fadeTo("slow", 1.0); 
			});	
}

function hoverbuttonReverse(){
		jQuery(".clearborder").hover(function(){
			jQuery(this).stop().fadeTo("fast", 1);
			},function(){
			jQuery(this).stop().fadeTo("medium", 0.7); 
			});
		
}




			var i = 0;//initialize
			var int=0;//Internet Explorer Fix
			jQuery(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
			var int = setInterval("doThis(i)",200);//500 is the fade in speed in milliseconds
			});

			function doThis() {
			var images = jQuery('img').length;//count the number of images on the page
			if (i >= images) {// Loop the images
			clearInterval(int);//When it reaches the last image the loop ends
			}
			jQuery('.preloader img:hidden').eq(0).fadeIn(500);//fades in the hidden images one by one
			i++;//add 1 to the count
	}
	

// Reverses the z-indexing for correcting ie7 z-index issues
/*$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		$(this).css('zIndex', zIndexNumber);
		zIndexNumber -= 10;
	});
});*/


	
	

// JavaScript Document

/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}


/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}

/**
*
*	simpleTooltip jQuery plugin, by Marius ILIE
*	visit http://dev.mariusilie.net for details
*
**/
(function($){ $.fn.simpletooltip = function(){
	return this.each(function() {
		var text = $(this).attr("title");
		$(this).attr("title", "");
		if(text != undefined) {
			$(this).hover(function(e){
				var tipX = e.pageX + 12;
				var tipY = e.pageY + 12;
				$(this).attr("title", ""); 
				$("body").append("<div id='simpleTooltip' style='position:absolute; z-index: 9999; display: none;'>" + text + "</div>");
				if($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
				else var tipWidth = $("#simpleTooltip").width()
				$("#simpleTooltip").width(tipWidth);
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			}, function(){
				$("#simpleTooltip").remove();
				$(this).attr("title", text);
			});
			$(this).mousemove(function(e){
				var tipX = e.pageX - 10;
				var tipY = e.pageY - 40;
				var tipWidth = $("#simpleTooltip").outerWidth(true);
				var tipHeight = $("#simpleTooltip").outerHeight(true);
				if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
				if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
				$("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
			});
		}
	});
}})(jQuery);

$(function() {
	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});
});

function stopCycle() {
	  
    $('#cycle').cycle({
       
        timeout:0,
 			pause:1
	 });

  };

function startCycle() {
	
		var $slider_effect = jQuery("meta[name=slider_effect]").attr('content');
		var $slider_timeout = jQuery("meta[name=slider_timeout]").attr('content');
	
    $('#cycle img:first').fadeIn(1000, function() {	  
    $('#cycle').cycle({
        fx: $slider_effect,
        speed:300,
		  easing: 'easeInOutQuad',
		  cleartype:  1,
		  pause:1,
        timeout: $slider_timeout,
        pager:  '#nav',
        pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav li:eq(' + idx + ') a'; 
		
    } 
	 
					
    });
	 
	 $('#pauseButton').click(function() { 
    $('#cycle').cycle('pause'); 
	});
	 
	 $('#resumeButton').click(function() { 
    $('#cycle').cycle('resume'); 
	});
	 
	 
	 });

  };


