/* ------------------------------------------------------------------------
	function.js
 * jQuery plugins
	
------------------------------------------------------------------------- */


	$(document).ready(function(){
		$('.casting-model-search').live('click',function(){
		
			doLoad('casting_save','casting-model-search',document.getElementById('frm_casting'));
		});
		//	SCROLL / sidebar
		window.onscroll = function()
		{
			if( window.XMLHttpRequest ) { // IE 6 doesn't implement position fixed nicely...
				if (document.documentElement.scrollTop > 282 || self.pageYOffset > 282) {
					$('#sticky-menu').css('position', 'fixed');
					$('#sticky-menu').css('top', '120px');
					$('#content_sub-top').css('position', 'fixed');
					$('#content_sub-top').css('top', '0');
				} else if (document.documentElement.scrollTop < 282 || self.pageYOffset < 282) {
					$('#sticky-menu').css('position', 'absolute');
					$('#sticky-menu').css('top', '402px');
					$('#content_sub-top').css('position', 'absolute');
					$('#content_sub-top').css('top', '282px');
				}
			}
			
		}

		//	BUTTON CASHA
		$('div.casha').live('click',function() {
			var flag = $(this).attr('flag');
			if(flag==0){
				$(this).addClass('casha-active');
				$(this).attr('flag',1);
			
				$(this).html('модель выбрана');
				doLoad('debug','add_to_favorite',{id:$(this).attr('rel')});
			}
			else{
				$(this).removeClass('casha-active');
				$(this).attr('flag',0);
				$(this).html('выбрать модель');
				doLoad('debug','remove_to_favorite',{id:$(this).attr('rel')});
			}
		});

		//	FADE / pic
		if ($.browser.msie && $.browser.version < 7) return;
			
		$('li.item')
			//.removeClass('highlight')
			//.find('a')
			.append('<div class="hidden" />').each(function () {
				var $div = $('div.hidden', this).css('opacity', 0);
				$(this).hover(function () {
					$div.stop().fadeTo(200, 1);
					if ($.browser.msie) $div.stop().fadeTo(200, 0.8);
					//$('a', this).css('cursor', 'help');
				}, function () {
					$div.stop().fadeTo(200, 0);
				});
			});

		//	SCROLL / Toggle-Cookie
		function setDisplayOption(toggleObject, cookieName) {
			if (($.cookie(cookieName) == 0) || ($.cookie(cookieName) == null)) {
				$(toggleObject).css('display', 'none');
			} else {
				$(toggleObject).css('display', 'block');
			} 
		}
				
		function addToggleWithCookie(toggleLink, toggleObject, cookieName) {
			var cookieValue;
			setDisplayOption(toggleObject, cookieName);
			$(toggleLink).click(function() {
				if ($.cookie(cookieName) == null) {
					cookieValue = 1;
				} 
				else {
					cookieValue = Math.abs($.cookie(cookieName) - 1);
				}
				$.cookie(cookieName, cookieValue, { path: '/', expires: 7 });
					//$(toggleObject).toggle("slow");
					$(toggleObject).slideToggle("slow");
			});
		}	
		//addToggleWithCookie('#fade0', 'form.select-model', 'search_toggle');
		addToggleWithCookie('#fadeImg2', 'div.slide-block-footer', 'comments_toggle');

		//	s3Slider
		$('#slider1').s3Slider({
			timeOut: 4000 
		});
		
		//	lazyload
		$('div.parent img').lazyload({
			placeholder : '/img/grey.gif', effect : 'fadeIn'
		});

	});
	
	
/* ------------------------------------------------------------------------
	page-user, page-models
 * class = user-my-page
	
------------------------------------------------------------------------- */
	function show(path)
		{ 
		if (obj = document.getElementById('user-pic')) { 
		obj.src = path; } 
	}
	
/* ------------------------------------------------------------------------
	page-user-profile
 * add photo
	
------------------------------------------------------------------------- */
	function append() {  
      var newItem = document.createElement("input");
      newItem.setAttribute('type','file');       
      newItem.setAttribute('name','UF[]');               
      document.getElementById("my_list_photos").appendChild(newItem);
   	  newItem = document.createElement("br");
      document.getElementById("my_list_photos").appendChild(newItem);
	}
	
